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

import com.brilliance.isc.bo.Cbb;
import com.brilliance.isc.common.api.diary.vo.DiaryRequestVo;
import com.brilliance.isc.common.liaallg.vo.LiaallgVo;
import com.brilliance.isc.common.setfeg.vo.SetfegVo;
import com.brilliance.isc.common.trndoc.vo.DoceotVo;
import com.brilliance.isc.common.vo.*;
import lombok.Data;

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


@Data
public class TrndiaVo extends AbstractCommonVo {

    private List<DiaVo> dias;

    //业务摘要信息
    private BizInfoVo rec;

    //业务修改摘要信息
    private BizAmdInfoVo amdRec;

    //CBB列表
    private Map<String, Cbb> cbsMap;

    //交易角色参与方列表
    private List<PtsptaVo> ptsList;

    //表外条目
    private List<LiaallgVo> liaallg;

    //注册简易交易模型列表
    private List<SimpleModuleVo> registerSimpleModules;

    //是否读取过前手数据 X表示已经读取过
    private String oldredflg;

    //结算金额 来源setmod.setamt
    private BigDecimal setamt = BigDecimal.ZERO;

    //结算币种
    private String setcur = "";

    private SetfegVo setfeg;

    //报文面函条目
    private List<DoceotVo> doceot;

    public TrndiaVo(){}

    public TrndiaVo(DiaryRequestVo diaryRequest) {
        this.dias = diaryRequest.getDias();
        this.rec = diaryRequest.getRec();
        this.amdRec = diaryRequest.getAmdRec();
        this.cbsMap = diaryRequest.getCbsMap();
        this.ptsList = diaryRequest.getPtsList();
        this.liaallg = diaryRequest.getLiaallg();
        this.oldredflg = diaryRequest.getOldredflg();
        this.setamt = diaryRequest.getSetamt();
        this.setcur = diaryRequest.getSetcur();
        this.setfeg = diaryRequest.getSetfeg();
        this.doceot = diaryRequest.getDoceot();
    }

    public void addRegisterModule(SimpleModuleVo simpleModuleVo) {
        if (simpleModuleVo == null) {
            return;
        }
        if (registerSimpleModules == null) {
            registerSimpleModules = new ArrayList<>();
        }
        boolean findFlag = false;
        for (SimpleModuleVo module : registerSimpleModules) {
            if (module.getObjinr().equals(simpleModuleVo.getObjinr())
                    && module.getObjtyp().equals(simpleModuleVo.getObjtyp())) {
                findFlag = true;
                break;
            }
        }
        if (!findFlag) {
            registerSimpleModules.add(simpleModuleVo);
        }
    }

    @Override
    public void reset() {
        if (rec == null) {
            rec = new BizInfoVo();
        }
        if (amdRec == null) {
            amdRec = new BizAmdInfoVo();
        }
        if (cbsMap == null) {
            cbsMap = new HashMap<>();
        }
        if (ptsList == null) {
            ptsList = new ArrayList<>();
        }
        if (dias == null) {
            dias = new ArrayList<>();
        }
    }
}
