package com.wayne.www.waynelib.webservice.entity;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.wayne.www.waynelib.listener.NotifyPropertyChanged;
import com.wayne.www.waynelib.qa_ipos_biz.FuelItemTagBean;
import com.wayne.www.waynelib.util.HsLogTagFlag;
import com.wayne.www.waynelib.util.HsLogUtils;
import com.wayne.www.waynelib.util.Util;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * Created by Shawn on 6/8/2017.
 */

public class PosTrxItem extends NotifyPropertyChanged implements Serializable {
    @SerializedName("Id")
    private String id;
    @SerializedName("LineNum")
    private int lineNum;
    @SerializedName("PosItemId")
    private String posItemUniqueId;
    @SerializedName("Qty")
    private BigDecimal qty;
    @SerializedName("PosTrxId")
    private String posTrxId;
    @SerializedName("Item")
    private PosItem posItem;
    @SerializedName("GrossAmount")
    private BigDecimal grossAmount;

    @SerializedName("NetAmount")
    private BigDecimal netAmount;

    @SerializedName("Voided")
    private boolean voided;

    @SerializedName("FuelItemSoldOnPumpId")
    private Integer fuelItemSoldOnPumpId;
    @SerializedName("FuelItemSoldOnPumpNozzleId")
    private Integer fuelItemSoldOnPumpNozzleId;

    @SerializedName("FuelItemOriginalGrossAmount")
    private BigDecimal fuelItemOriginalGrossAmount;

    @SerializedName("FuelItemFdcTransactionSeqNo")
    private String fuelItemFdcTransactionSeqNo;
    @SerializedName("FuelItemFdcReleaseTokenAttribute")
    private Integer fuelItemFdcReleaseTokenAttribute;

    //{\"TagSystemName\":\"SmartFuelIcCardSystem\",\"TagType\":\"SmartFuelIcCard\",\"TagId\":\"11000419901000003474\",\"TagLinkedServiceIdentityUser\":null,\"Detail\":\" real pump is authorized by an attandant's smartFuel IC card\"}
    private String FuelItemTag;//返回的是json字符串

    public PosItem getPosItem() {
        return this.posItem;
    }

    public BigDecimal getNetAmount() {
        return netAmount;
    }

    public void setPosItem(PosItem posItem) {
        this.posItem = posItem;
    }

    public void setLineNum(int lineNum) {
        this.lineNum = lineNum;
    }

    public int getLineNum() {
        return this.lineNum;
    }

    public String getFuelItemTag() {
        return FuelItemTag;
    }

    public String getQty() {
        if (this.qty == null) return "0";
        return Util.use(this.qty.toString());
    }

    public String getGrossAmount() {
        if (this.grossAmount == null) return "0";
        return Util.use(this.grossAmount.toString());
    }

    public boolean getVoided() {
        return this.voided;
    }

    public Integer getFuelItemSoldOnPumpId() {
        return this.fuelItemSoldOnPumpId;
    }

    public Integer getFuelItemSoldOnPumpNozzleId() {
        return this.fuelItemSoldOnPumpNozzleId;
    }

    public String getFuelItemOriginalGrossAmount() {
        if (this.fuelItemOriginalGrossAmount == null) return "0";
        return this.fuelItemOriginalGrossAmount.toString();
    }

    public String getFuelItemFdcTransactionSeqNo() {
        return this.fuelItemFdcTransactionSeqNo;
    }

    public Integer getFuelItemFdcReleaseTokenAttribute() {
        return this.fuelItemFdcReleaseTokenAttribute;
    }

    public String getMyNetAmount() {
        if (netAmount == null) return "0.00";
        return Util.use(netAmount.toString());
    }

    //int index = item.FuelItemTag.IndexOf("TagId");
//   string cardNo = item.FuelItemTag.Substring(index + 8,20);
    public String getCardNo() {
        if (FuelItemTag == null) return "FuelItemTag is null";
        try {
            FuelItemTagBean ftb = new Gson().fromJson(FuelItemTag, FuelItemTagBean.class);
            if (!TextUtils.isEmpty(ftb.getTagId()))
                return ftb.getTagId();
        } catch (Exception e) {
            HsLogUtils.o(HsLogTagFlag.NET_RETROFIT, e.getMessage());
        }
        return "data is no json String";
    }

    /**
     * @desc 是否有tagId存在（代表员工卡号）
     * @info Created by LzPeng on 2020/4/26 14:46
     */
    public boolean isHaveTagId() {
        return !TextUtils.isEmpty(FuelItemTag) && FuelItemTag.contains("TagId");
    }

}
