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

import com.google.gson.annotations.SerializedName;
import com.wayne.www.waynelib.util.DateUtils;
import com.wayne.www.waynelib.util.Util;

import org.jetbrains.annotations.Nullable;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

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

public class ClientRingUpPosItem {
    /**
     * database unique id
     */
    @SerializedName("PosItemUniqueId")
    private String posItemUniqueId;
    @SerializedName("Qty")
    private BigDecimal qty;
    @SerializedName("ClientRingUpTime")
    private String clientRingUpTime;

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

    @SerializedName("FuelItemOriginalGrossAmount")
    private BigDecimal fuelItemOriginalGrossAmount;

    @SerializedName("FuelItemClientSideItemId")
    private Integer fuelItemClientSideItemId;
    @SerializedName("FuelItemClientSidePrice")
    private Double fuelItemClientSidePrice;
    @SerializedName("FuelItemFdcTransactionSeqNo")
    private String fuelItemFdcTransactionSeqNo;
    @SerializedName("FuelItemFdcReleaseTokenAttribute")
    private Integer fuelItemFdcReleaseTokenAttribute;

    @SerializedName("FuelItemPumpTotalizerMoney")
    private BigDecimal fuelItemPumpTotalizerMoney;
    @SerializedName("FuelItemPumpTotalizerVolume")
    private BigDecimal fuelItemPumpTotalizerVolume;

    @SerializedName("VoidOperationForWhichLineNum")
    private Integer voidOperationForWhichLineNum;

    @SerializedName("TransactionComment")
    private String transactionComment;

    @SerializedName("FuelItemTransactionEndTime")
    private String fuelItemTransactionEndTime;

    public ClientRingUpPosItem() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentDateandTime = sdf.format(new Date());
        this.clientRingUpTime = currentDateandTime;
    }

    public void setPosItemUniqueId(String id) {
        this.posItemUniqueId = id;
    }

    public String getPosItemUniqueId() {
        return this.posItemUniqueId;
    }

    public void setQty(String qty) {
        this.qty = new BigDecimal(qty);
    }

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


    public void setFuelItemSoldOnPumpId(Integer pumpId) {
        this.fuelItemSoldOnPumpId = pumpId;
    }

    public void setFuelItemSoldOnPumpNozzleId(Integer nozzleId) {
        this.fuelItemSoldOnPumpNozzleId = nozzleId;
    }

    public void setFuelItemClientSideItemId(int clientItemId) {
        this.fuelItemClientSideItemId = clientItemId;
    }

    public void setFuelItemClientSidePrice(double clientPrice) {
        this.fuelItemClientSidePrice = clientPrice;
    }

    /// <summary>
    /// the amount which calculated by local FC, typically Fuel item's amount should not re-cacualted in server again(by Qty*Price, may cause rounding issue),
    /// just trust the value from local.
    /// </summary>
    public void setFuelItemOriginalGrossAmount(BigDecimal grossAmount) {
        this.fuelItemOriginalGrossAmount = grossAmount;
    }

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

    public void setFuelItemFdcTransactionSeqNo(String seqNo) {
        this.fuelItemFdcTransactionSeqNo = seqNo;
    }

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

    public void setFuelItemFdcReleaseTokenAttribute(Integer releaseTokenAttribute) {
        this.fuelItemFdcReleaseTokenAttribute = releaseTokenAttribute;
    }

    public void setFuelItemPumpTotalizerMoney(BigDecimal pumpTotalizerMoney) {
        this.fuelItemPumpTotalizerMoney = pumpTotalizerMoney;
    }

    public void setFuelItemPumpTotalizerVolume(BigDecimal pumpTotalizerVolume) {
        this.fuelItemPumpTotalizerVolume = pumpTotalizerVolume;
    }

    public String getTransactionComment() {
        return this.transactionComment;
    }

    public void setTransactionComment(String value) {
        this.transactionComment = value;
    }

    public void setFuelItemTransactionEndTime(@Nullable Calendar transactionTimeStamp) {
        this.fuelItemTransactionEndTime = Util.convertCalendarToString(transactionTimeStamp);
    }

    public void setFuelItemTransactionEndTime(String fuelItemTransactionEndTime) {
        if (fuelItemTransactionEndTime.lastIndexOf(".") != -1 && fuelItemTransactionEndTime.contains("T")) {
            this.fuelItemTransactionEndTime = fuelItemTransactionEndTime.substring(0, fuelItemTransactionEndTime.lastIndexOf("."))
                    .replace("T", " ");
        } else {
            this.fuelItemTransactionEndTime = fuelItemTransactionEndTime;
        }

    }
}