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


import com.brilliance.mda.runtime.mda.CodetableItem;
import com.brilliance.mda.runtime.mda.util.Decimals;
import com.brilliance.isc.bo.Cbb;
import com.brilliance.isc.common.api.liaall.vo.LiaallRequest;
import com.brilliance.isc.common.liaallg.vo.LiaallgVo;
import com.brilliance.isc.common.liaallr.vo.LiaallrVo;
import com.brilliance.isc.common.liaccv.vo.LiaccvgVo;
import com.brilliance.isc.common.vo.AbstractCommonVo;
import com.brilliance.isc.common.vo.BizAmdInfoVo;
import com.brilliance.isc.common.vo.BizInfoVo;
import com.brilliance.isc.common.vo.PtsptaVo;
import com.brilliance.isc.vo.component.trtcre.TrtcreVo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

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

@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class LiaallVo extends AbstractCommonVo implements Serializable {

    private List<LiaccvgVo> liaccvg;

    private BizInfoVo rec;

    private BizAmdInfoVo amdRec;

    private Map<String, Cbb> cbsMap;

    private List<PtsptaVo> ptsList;

    private String concur = NULLSTR;

    private String tenset = NULLSTR;

    //Group key for LiaallSetCbeAmountDivAvlAvsInt
    private String avxgrpkey = NULLSTR;

    private BigDecimal outpct = Decimals.ZERO_SCALE6;

    private BigDecimal outamt = Decimals.ZERO_SCALE2;

    private BigDecimal misamt = Decimals.ZERO_SCALE2;

    private int misidx;

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date tensetmatdat;

    private List<TenorSettleVo> tenorSettles;

    //承兑列表
    private List<AcceptLineVo> acceptLines;

    private BigDecimal acpamt = Decimals.ZERO_SCALE2;

    private BigDecimal exttotamt = Decimals.ZERO_SCALE2;

    //Amount of settled tenor
    private BigDecimal tensetamt = Decimals.ZERO_SCALE2;

    private BigDecimal exttotoldamt = Decimals.ZERO_SCALE2;

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

    private List<LiaallgVo> liaallg;

    public LiaallVo(LiaallRequest liaallRequest) {
        this.rec = liaallRequest.getRec();
        this.amdRec = liaallRequest.getAmdRec();
        this.cbsMap = liaallRequest.getCbsMap();
        this.ptsList = liaallRequest.getPtsList();
        this.liaallg = liaallRequest.getLiaallg();
        this.liaccvg = liaallRequest.getLiaccvg();
        this.oldredflg = liaallRequest.getOldredflg();
        this.tenorSettles = liaallRequest.getTenorSettles();
        this.tensetamt = liaallRequest.getTensetamt();
        this.tenset = liaallRequest.getTenset();
        this.tensetmatdat = liaallRequest.getTensetmatdat();
    }

    private List<LiaallrVo> liaallr;

    private String doccur = NULLSTR;

    private BigDecimal docamt = Decimals.ZERO_SCALE2;

    //Description of roles
    private List<CodetableItem> roldsc = null;

    //默认我方费用收取角色
    private String feeclirol = NULLSTR;

    //默认对手费用收取角色
    private String feecorrol = NULLSTR;

    @Override
    public void reset() {
        if (outpct == null) {
            outpct = Decimals.ZERO_SCALE6;
        }
        if (outamt == null) {
            outamt = Decimals.ZERO_SCALE2;
        }
        if (misamt == null) {
            misamt = Decimals.ZERO_SCALE2;
        }
        if (acpamt == null) {
            acpamt = Decimals.ZERO_SCALE2;
        }
        if (exttotamt == null) {
            exttotamt = Decimals.ZERO_SCALE2;
        }
        if (tensetamt == null) {
            tensetamt = Decimals.ZERO_SCALE2;
        }
        if (exttotoldamt == null) {
            exttotoldamt = Decimals.ZERO_SCALE2;
        }
        if (liaallg == null) {
            liaallg = new ArrayList<>();
        }
        if (ptsList == null) {
            ptsList = new ArrayList<>();
        }
        liaallg.forEach(liaallgVo -> liaallgVo.reset());
        if (liaallr == null) {
            liaallr = new ArrayList<>();
        }
        liaallr.forEach(liaallrVo -> liaallrVo.reset());
        if (roldsc == null) {
            roldsc = new ArrayList<>();
        }
        if (liaccvg == null) {
            liaccvg = new ArrayList<>();
        }
        if (tenorSettles == null) {
            tenorSettles = new ArrayList<>();
        }
        if (acceptLines == null) {
            acceptLines = new ArrayList<>();
        }
    }
}
