package com.brilliance.isc.common.liaccv.vo;

import com.brilliance.mda.runtime.mda.IStream;
import com.brilliance.mda.runtime.mda.impl.StreamImpl;
import com.brilliance.mda.runtime.mda.util.Decimals;
import com.brilliance.mda.support.jakson.serialize.BigDecimalSerializeRate;
import com.brilliance.mda.support.jakson.serialize.DecimalLength;
import com.brilliance.isc.bo.Cbb;
import com.brilliance.isc.common.api.liaccv.vo.LiaccvRequest;
import com.brilliance.isc.common.vo.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.brilliance.mda.runtime.mda.Constants.NULLSTR;

@Data
@ApiModel(value = "保证金信息", description = "保证金信息")
@JsonIgnoreProperties(ignoreUnknown = true)
@NoArgsConstructor
public class LiaccvVo extends AbstractCommonVo {

    private BizInfoVo rec;
    private BizAmdInfoVo amdRec;
    private Map<String, Cbb> cbsMap;
    private List<PtsptaVo> ptsList;
    private List<LiaccvgVo> liaccvg;
    //Currency of open Amount of contract
    private String oldcur = NULLSTR;
    private IStream parstm = new StreamImpl();

    private BigDecimal oldamt = Decimals.ZERO_SCALE2;

    private BigDecimal oldresamt = Decimals.ZERO_SCALE2;
    //New base amount for cash cover
    private BigDecimal newamt = Decimals.ZERO_SCALE2;

    //output
    @ApiModelProperty(value = "单据币种", name = "doccur")
    private String concur;
    @ApiModelProperty(value = "", name = "canflg")
    //Create gle flag
    private String gleflg;

    //Change currency flag
    private String chgcurflg;
    private String canflg;
    @ApiModelProperty(value = "", name = "objmodpath")
    private String objmodpath;
    @ApiModelProperty(value = "", name = "chgamt")
    private BigDecimal chgamt = Decimals.ZERO_SCALE2;
    @ApiModelProperty(value = "", name = "newrol")
    private String newrol;
    @ApiModelProperty(value = "", name = "chgresamt")
    private BigDecimal chgresamt = Decimals.ZERO_SCALE2;

    @ApiModelProperty(value = "", name = "totcovamt", required = true)
    private BigDecimal totcovamt = Decimals.ZERO_SCALE2;
    //保证金实收比例
    @JsonSerialize(using = BigDecimalSerializeRate.class)
    @DecimalLength(2)
    private  BigDecimal relcshpct = Decimals.ZERO_SCALE2;
    //保证金应收比例
    @JsonSerialize(using = BigDecimalSerializeRate.class)
    @DecimalLength(2)
    private BigDecimal cshpct = Decimals.ZERO_SCALE2;
    //交易是否闭卷
    private String closesta = NULLSTR;
    //New base amount reserved for subcontracts
    private BigDecimal newresamt = Decimals.ZERO_SCALE2;
    //reserve amount based percent
    private BigDecimal pctresamt = Decimals.ZERO_SCALE2;
    //Additional Information e.g. about forward contracts
    private String addinf = NULLSTR;

    private FcdVo fcdVo;

    private DnfmodVo dnfmodVo;

    private String doccur;

    private BigDecimal docamt = BigDecimal.ZERO;

    //old info read X表示已经读了old
    private String oldredflg = NULLSTR;

    private String macold = "";

    /**
     *  增加保证金按钮
     */
    private String addbut = "N";

    /**
     * 记账按钮
     */
    private String glebut = "N";

    /**
     * cbe 列表
     */
    private String cbeListJson = "";

    public LiaccvVo(LiaccvRequest liaccvRequest) {
        this.rec = liaccvRequest.getRec();
        this.amdRec = liaccvRequest.getAmdRec();
        this.cbsMap = liaccvRequest.getCbsMap();
        this.ptsList = liaccvRequest.getPtsList();
        this.liaccvg = liaccvRequest.getLiaccvg();
        this.fcdVo = liaccvRequest.getFcdVo();
        this.oldcur = liaccvRequest.getOldcur();
        this.oldamt = liaccvRequest.getOldamt();
        this.chgamt = liaccvRequest.getChgamt();
        this.concur = liaccvRequest.getConcur();
        this.gleflg = liaccvRequest.getGleflg();
        this.chgcurflg = liaccvRequest.getChgcurflg();
        this.newrol = liaccvRequest.getNewrol();
        this.oldredflg = liaccvRequest.getOldredflg();
        this.cshpct = liaccvRequest.getCshpct();
        this.oldresamt = liaccvRequest.getOldresamt();
        this.chgresamt = liaccvRequest.getChgresamt();
        this.macold = liaccvRequest.getMacold();
        this.objmodpath = liaccvRequest.getObjmodpath();
        this.newamt = liaccvRequest.getNewamt();
        this.newresamt = liaccvRequest.getNewresamt();
        this.relcshpct = liaccvRequest.getRelcshpct();
        this.pctresamt = liaccvRequest.getPctresamt();
        this.totcovamt = liaccvRequest.getTotcovamt();
        this.addinf = liaccvRequest.getAddinf();
        this.cbeListJson = liaccvRequest.getCbeListJson();
        this.setModifySet(liaccvRequest.getModifySet());
    }

    @Override
    public void reset() {
        if (oldamt == null) {
            oldamt = Decimals.ZERO_SCALE2;
        }
        if (oldresamt == null) {
            oldresamt = Decimals.ZERO_SCALE2;
        }
        if (chgamt == null) {
            chgamt = Decimals.ZERO_SCALE2;
        }
        if (chgresamt == null) {
            chgresamt = Decimals.ZERO_SCALE2;
        }
        if (totcovamt == null) {
            totcovamt = Decimals.ZERO_SCALE2;
        }
        if (parstm == null) {
            parstm = new StreamImpl();
        }
        if (newamt == null) {
            newamt = Decimals.ZERO_SCALE2;
        }
        if (newresamt == null) {
            newresamt = Decimals.ZERO_SCALE2;
        }
        if (pctresamt == null) {
            pctresamt = Decimals.ZERO_SCALE2;
        }
        if (liaccvg == null) {
            liaccvg = new ArrayList<>();
        }
        liaccvg.forEach(liaccvgVo -> liaccvgVo.reset());
        if (dnfmodVo == null) {
            dnfmodVo = new DnfmodVo();
        }
        if (relcshpct == null) {
            relcshpct = Decimals.ZERO_SCALE6;
        }
        if (cshpct == null) {
            cshpct = Decimals.ZERO_SCALE6;
        }
    }
}
