package com.brilliance.isc.common.converter;

import com.brilliance.isc.bo.Cbb;
import com.brilliance.isc.bo.Smh;
import com.brilliance.isc.bo.Spt;
import com.brilliance.isc.bo.model.*;
import com.brilliance.isc.common.glemod.vo.GlemodVo;
import com.brilliance.isc.common.jshmod.vo.JshmodRequest;
import com.brilliance.isc.common.lgbdet.vo.LgbdetVo;
import com.brilliance.isc.common.liaall.vo.LiaallVo;
import com.brilliance.isc.common.liaallg.vo.LiaallgVo;
import com.brilliance.isc.common.liaccv.vo.LiaccvVo;
import com.brilliance.isc.common.liaccv.vo.LiaccvgVo;
import com.brilliance.isc.common.limmod.vo.LimmodVo;
import com.brilliance.isc.common.limmod.vo.YpnmodVo;
import com.brilliance.isc.common.monmod.vo.MonmodVo;
import com.brilliance.isc.common.rmbbop.vo.RmbbopRequest;
import com.brilliance.isc.common.setfeg.vo.SetfegVo;
import com.brilliance.isc.common.setfog.vo.SetfogVo;
import com.brilliance.isc.common.setglg.vo.SetglgVo;
import com.brilliance.isc.common.setmod.vo.SetmodVo;
import com.brilliance.isc.common.transaction.help.TransactionServiceSet;
import com.brilliance.isc.common.transaction.vo.BaseTransactionVo;
import com.brilliance.isc.common.trndia.vo.TrndiaVo;
import com.brilliance.isc.common.trndoc.vo.DoceotVo;
import com.brilliance.isc.common.trndoc.vo.TrndocVo;
import com.brilliance.isc.common.trnmod.vo.TrnmodVo;
import com.brilliance.isc.common.umdmod.vo.UmdmodVo;
import com.brilliance.isc.common.util.Utils;
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.utils.BeanUtils;
import com.brilliance.isc.vo.CipmodVo;
import com.brilliance.isc.vo.HvpmodVo;
import com.brilliance.isc.vo.model.AttpVo;
import com.brilliance.isc.vo.model.DftcreBizInfoVo;
import com.brilliance.isc.vo.model.TrtcreBizInfoVo;
import com.brilliance.mda.runtime.mda.util.MdaUtils;

import java.util.List;
import java.util.Map;

public class BaseComponentBuilder {

    public static LiaccvVo buildLiaccvVo(List<LiaccvgVo> liaccvg, BizInfoVo rec, BizAmdInfoVo amdRec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList) {
        LiaccvVo liaccv = new LiaccvVo();
        liaccv.setLiaccvg(liaccvg);
        liaccv.setRec(rec);
        liaccv.setAmdRec(amdRec);
        liaccv.setCbsMap(cbsMap);
        liaccv.setPtsList(ptsptaList);
        return liaccv;
    }

    public static LiaallVo buildLiaallVo(List<LiaallgVo> liaallg, List<LiaccvgVo> liaccvg, BizInfoVo rec, BizAmdInfoVo amdRec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList) {
        LiaallVo liaall = new LiaallVo();
        liaall.setLiaallg(liaallg);
        liaall.setLiaccvg(liaccvg);
        liaall.setRec(rec);
        liaall.setAmdRec(amdRec);
        liaall.setCbsMap(cbsMap);
        liaall.setPtsList(ptsptaList);
        return liaall;
    }

    public static LgbdetVo buildLgbdetVo(BizInfoVo rec, Map<String, Cbb> cbsMap) {
        LgbdetVo lgbdet = new LgbdetVo();
        lgbdet.setRec(rec);
        lgbdet.setCbsMap(cbsMap);
        return lgbdet;
    }

    public static SetmodVo buildSetmodVo(BizInfoVo rec, BizAmdInfoVo amdRec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList, SetfogVo setfogVo, SetfegVo setfegVo, SetglgVo setglgVo) {
        SetmodVo setmod = new SetmodVo();
        setmod.setRec(rec);
        setmod.setAmdRec(amdRec);
        setmod.setCbsMap(cbsMap);
        setmod.setPtsList(ptsptaList);
        setmod.setSetfog(setfogVo);
        setmod.setSetfeg(setfegVo);
        setmod.setSetglg(setglgVo);
        return setmod;
    }

    public static void fillTrtcre(Trtcre trtcre, BizInfoVo rec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList, List<LiaccvgVo> liaccvg) {
        TrtcreBizInfoVo trtcreBizInfoVo = new TrtcreBizInfoVo();
        trtcre.setRec(trtcreBizInfoVo);
        BeanUtils.copyProperties(rec, trtcre.getRec());
        trtcre.setCbsMap(cbsMap);
        trtcre.setPtsptaList(ptsptaList);
        trtcre.setLiaccvg(liaccvg);
    }

    public static void fillDftcre(Dftcre dftcre, BizInfoVo rec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList) {
        DftcreBizInfoVo dftcreBizInfoVo = new DftcreBizInfoVo();
        dftcre.setRec(dftcreBizInfoVo);
        BeanUtils.copyProperties(rec, dftcre.getRec());
        dftcre.setCbsMap(cbsMap);
        dftcre.setPtsptaList(ptsptaList);
    }

    /**
     * 构造SetmodVo对象 根据SimpleSetmodVo 和 Setfog setfeg setglg
     *
     * @param vo
     * @return
     */
    public static SetmodVo buildSetmodVo(BaseTransactionVo vo) {
        SetmodVo setmod = new SetmodVo();
        DtoMapper.INSTANCE.updateVoToBo(vo.getSetmod(), setmod);
        setmod.setSetfog(vo.getSetfog());
        setmod.setSetfeg(vo.getSetfeg());
        setmod.setSetglg(vo.getSetglg());
        return setmod;
    }

    public static LiaallVo buildLiaallVo(BaseTransactionVo vo) {
        LiaallVo liaall = new LiaallVo();
        DtoMapper.INSTANCE.updateVoToBo(vo.getLiaall(), liaall);
        liaall.setLiaallg(vo.getLiaallg());
        return liaall;
    }

    public static GlemodVo buildGlemodVo(BizInfoVo rec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList) {
        GlemodVo glemod = new GlemodVo();
        glemod.setRec(rec);
        glemod.setCbsMap(cbsMap);
        glemod.setPtsList(ptsptaList);
        return glemod;
    }

    public static TrnmodVo buildTrnmodVo(Spt spt, Smh smh) {
        TrnmodVo trnmod = new TrnmodVo();
        trnmod.setSpt(spt);
        trnmod.setSmh(smh);
        return trnmod;
    }

    public static TrndocVo buildTrndocVo(BizInfoVo rec, List<PtsptaVo> ptsptaList, Spt spt, List<DoceotVo> doceot) {
        TrndocVo trndocVo = new TrndocVo();
        trndocVo.setRec(rec);
        trndocVo.setPtsptas(ptsptaList);
        trndocVo.setSpt(spt);
        trndocVo.setDoceot(doceot);
        return trndocVo;
    }

    public static TrndiaVo buildTrndiaVo(BizInfoVo rec, BizAmdInfoVo amdRec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList, BaseTransactionVo vo) {
        TrndiaVo trndiaVo = new TrndiaVo();
        trndiaVo.setRec(rec);
        trndiaVo.setAmdRec(amdRec);
        trndiaVo.setCbsMap(cbsMap);
        trndiaVo.setPtsList(ptsptaList);
        trndiaVo.setDias(vo.getDias());
        trndiaVo.setLiaallg(vo.getLiaallg());
        trndiaVo.setOldredflg(vo.getTrndia().getOldredflg());
        trndiaVo.setSetamt(vo.getSetmod().getDocamt());
        trndiaVo.setSetcur(vo.getSetmod().getDoccur());
        trndiaVo.setSetfeg(vo.getSetfeg());
        trndiaVo.setDoceot(vo.getDoceot());
        return trndiaVo;
    }

    public static UmdmodVo buildUmdmodVo(BizInfoVo rec, BizAmdInfoVo amdrec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList, List<Ptsaddg> ptsaddg, BaseTransactionVo baseTransactionVo) {
        UmdmodVo umdmodVo = new UmdmodVo();
        umdmodVo.setAmdRec(amdrec);
        umdmodVo.setRec(rec);
        umdmodVo.setCbsMap(cbsMap);
        umdmodVo.setPtsptas(ptsptaList);
        umdmodVo.setPtsaddg(ptsaddg);
        umdmodVo.setBennam(baseTransactionVo.getUmdmod().getBennam());
        umdmodVo.setCipmodVo(Utils.getFieldValue(baseTransactionVo, "cipmodVo"));
        umdmodVo.setSetglgVo(baseTransactionVo.getSetglg());
        return umdmodVo;
    }

    public static LimmodVo buildLimmodVo(BizInfoVo rec, BizAmdInfoVo amdrec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList, LiaallVo liaallVo, LiaccvVo liaccvVo, BaseTransactionVo baseTransactionVo) {
        LimmodVo limmodVo = new LimmodVo();
        limmodVo.setCbsMap(cbsMap);
        limmodVo.setPtsList(ptsptaList);
        limmodVo.setRec(rec);
        limmodVo.setAmdRec(amdrec);
        limmodVo.setLiaall(liaallVo);
        limmodVo.setLiaccvVo(liaccvVo);
        DtoMapper.INSTANCE.updateVoToBo(baseTransactionVo.getLimmod(), limmodVo);
        limmodVo.reset();
        return limmodVo;
    }

    public static YpnmodVo buildYpnmodVo(BizInfoVo rec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList, BaseTransactionVo baseTransactionVo) {
        YpnmodVo ypnmodVo = new YpnmodVo();
        ypnmodVo.setCbsMap(cbsMap);
        ypnmodVo.setPtsList(ptsptaList);
        ypnmodVo.setRec(rec);
        ypnmodVo.setLimmod(baseTransactionVo.getLimmod());
        DtoMapper.INSTANCE.updateVoToBo(baseTransactionVo.getYpnmod(), ypnmodVo);
        ypnmodVo.reset();
        return ypnmodVo;
    }

    public static RmbbopRequest<BizInfoVo, BizAmdInfoVo> buildRmbbopRequest(BizInfoVo rec, BizAmdInfoVo amdRec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList, SetglgVo setglgVo, BaseTransactionVo baseTransactionVo) {
        RmbbopRequest<BizInfoVo, BizAmdInfoVo> rmbbopRequest = new RmbbopRequest<>();
        rmbbopRequest.reset();
        rmbbopRequest.setCbsMap(cbsMap);
        rmbbopRequest.setPtsList(ptsptaList);
        rmbbopRequest.setRec(rec);
        rmbbopRequest.setAmdRec(amdRec);
        rmbbopRequest.setSetglg(setglgVo);
        rmbbopRequest.setTransName(baseTransactionVo.getTransName());
        rmbbopRequest.setLiaallg(baseTransactionVo.getLiaallg());
        rmbbopRequest.setRmbbop(baseTransactionVo.getRmbbop());
        return rmbbopRequest;
    }

    public static MonmodVo buildMonmodRequest(BizInfoVo rec,List<PtsptaVo> ptsptaList, SetglgVo setglgVo) {
        MonmodVo monmodVo = new MonmodVo();
        monmodVo.reset();
        monmodVo.setPtsList(ptsptaList);
        monmodVo.setRec(rec);
        monmodVo.setSetglg(setglgVo);
        return monmodVo;
    }

    public static JshmodRequest<BizInfoVo> buildJshmodRequest(BizInfoVo rec, List<PtsptaVo> ptsptaList, Map<String, Cbb> cbsMap, SetmodVo setmodVo, BaseTransactionVo baseTransactionVo) {
        JshmodRequest<BizInfoVo> jshmodRequest = new JshmodRequest<>();
        jshmodRequest.reset();
        jshmodRequest.setPtsList(ptsptaList);
        jshmodRequest.setRec(rec);
        jshmodRequest.setCbsMap(cbsMap);
        jshmodRequest.setSetfeg(setmodVo.getSetfeg());
        jshmodRequest.setSetglg(setmodVo.getSetglg());
        jshmodRequest.setTransName(baseTransactionVo.getTransName());
        jshmodRequest.setJshmod(baseTransactionVo.getJshmod());
        return jshmodRequest;
    }

    public static Cfagit buildCfagit(BizInfoVo rec, BizAmdInfoVo amdRec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList, BaseTransactionVo baseTransactionVo) {
        Cfagit cfagit = new Cfagit();
        if (!MdaUtils.isEmpty(baseTransactionVo.getCfagit())) {
            cfagit = baseTransactionVo.getCfagit();
        }
        cfagit.reset();
        cfagit.setAmdRec(amdRec);
        cfagit.setPtsList(ptsptaList);
        cfagit.setRec(rec);
        cfagit.setCbsMap(cbsMap);
        cfagit.setRecgrp(baseTransactionVo.getCfagit().getRecgrp());
        cfagit.setTransName(baseTransactionVo.getTransName());

        return cfagit;
    }

    public static Cfabop buildCfabop(BizInfoVo rec, BizAmdInfoVo amdRec, Map<String, Cbb> cbsMap, List<PtsptaVo> ptsptaList, BaseTransactionVo baseTransactionVo) {
        Cfabop cfabop = new Cfabop();
        if (!MdaUtils.isEmpty(baseTransactionVo.getCfabop())) {
            cfabop = baseTransactionVo.getCfabop();
        }
        cfabop.reset();
        cfabop.setAmdRec(amdRec);
        cfabop.setPtsList(ptsptaList);
        cfabop.setRec(rec);
        cfabop.setCbsMap(cbsMap);
        cfabop.setCfaead(baseTransactionVo.getCfabop().getCfaead());
        cfabop.setCfaeaf(baseTransactionVo.getCfabop().getCfaeaf());
        cfabop.setCfaeca(baseTransactionVo.getCfabop().getCfaeca());
        cfabop.setTransName(baseTransactionVo.getTransName());

        return cfabop;
    }

    public static Bopgat buildBopgat(BizInfoVo rec, BizAmdInfoVo amdRec, TransactionServiceSet transactionServiceSet, BaseTransactionVo baseTransactionVo) {
        Bopgat bopgat = new Bopgat();
        if (!MdaUtils.isEmpty(baseTransactionVo.getBopgat())) {
            bopgat = baseTransactionVo.getBopgat();
        }
        bopgat.reset();
        bopgat.setRec(rec);
        bopgat.setAmdRec(amdRec);
        bopgat.setPtsList(transactionServiceSet.getPtsList());
        bopgat.setCbsMap(transactionServiceSet.getCbsMap());
        bopgat.setSetFelList(transactionServiceSet.getSetmodVo().getSetfeg().getSetfel());
        bopgat.setSetFolList(transactionServiceSet.getSetmodVo().getSetfog().getSetfol());
        bopgat.setSetgll(transactionServiceSet.getSetmodVo().getSetglg().getSetgll());
        bopgat.setTransName(baseTransactionVo.getTransName());
        CommetItems commetItems = buildCommetItems(baseTransactionVo);
        bopgat.setCommetItems(commetItems);
        return bopgat;
    }

    private static CommetItems buildCommetItems(BaseTransactionVo baseTransactionVo) {
        CommetItems commetItems = new CommetItems();
        Cpdgrp cpdgrp = Utils.getFieldValue(baseTransactionVo, "cpdgrp");
        CipmodVo cipmod = Utils.getFieldValue(baseTransactionVo, "cipmod");
        HvpmodVo hvpmod = Utils.getFieldValue(baseTransactionVo, "hvpmod");
        Cptp cptp = Utils.getFieldValue(baseTransactionVo, "cptp");
        AttpVo attp = Utils.getFieldValue(baseTransactionVo, "attp");
        commetItems.setV72(Utils.getFieldValue(baseTransactionVo, "swiadd//contag72"));
        if (!MdaUtils.isEmpty(cptp)) {
            commetItems.setCommet(cptp.getCommet());
        }
        if (!MdaUtils.isEmpty(cipmod)) {
            commetItems.setFuynh2(cipmod.getFuynh2());
            commetItems.setFuynh3(cipmod.getFuynh3());
            commetItems.setFuynh4(cipmod.getFuynh4());
            commetItems.setFuyns1(cipmod.getFuyns1());
            commetItems.setFuyns2(cipmod.getFuyns2());
            commetItems.setFuyns3(cipmod.getFuyns3());
            commetItems.setFuyns4(cipmod.getFuyns4());
            commetItems.setCovfuy1(cipmod.getCovfuy());
            commetItems.setCovfuy2(cipmod.getCovfy2());
            commetItems.setCovfuy3(cipmod.getCovfy3());
            commetItems.setCovfuy4(cipmod.getCovfy4());
        }
        if (!MdaUtils.isEmpty(hvpmod)) {
            commetItems.setFecomm(hvpmod.getFecomm());
        }
        if (!MdaUtils.isEmpty(attp)) {
            commetItems.setAttcommet(attp.getCommet());
            commetItems.setAttcommet72(attp.getCom102());
        }
        if (!MdaUtils.isEmpty(cpdgrp)) {
            commetItems.setContag72(cpdgrp.getBlk().getContag72());
        }
        return commetItems;
    }

    public static Boprem buildBoprem(BizInfoVo rec, BizAmdInfoVo amdRec, TransactionServiceSet transactionServiceSet, BaseTransactionVo baseTransactionVo) {
        Boprem boprem = new Boprem();
        if (!MdaUtils.isEmpty(baseTransactionVo.getBoprem())) {
            boprem = baseTransactionVo.getBoprem();
        }
        boprem.reset();
        boprem.setRec(rec);
        boprem.setAmdRec(amdRec);
        boprem.setPtsList(transactionServiceSet.getPtsList());
        boprem.setCbsMap(transactionServiceSet.getCbsMap());
        boprem.setSetFelList(transactionServiceSet.getSetmodVo().getSetfeg().getSetfel());
        boprem.setSetFolList(transactionServiceSet.getSetmodVo().getSetfog().getSetfol());
        boprem.setSetgll(transactionServiceSet.getSetmodVo().getSetglg().getSetgll());
        boprem.setTransName(baseTransactionVo.getTransName());
        CommetItems commetItems = buildCommetItems(baseTransactionVo);
        boprem.setCommetItems(commetItems);
        return boprem;
    }

    public static Boppay buildBoppay(BizInfoVo rec, BizAmdInfoVo amdRec, TransactionServiceSet transactionServiceSet, BaseTransactionVo baseTransactionVo) {
        Boppay boppay = new Boppay();
        if (!MdaUtils.isEmpty(baseTransactionVo.getBoppay())) {
            boppay = baseTransactionVo.getBoppay();
        }
        boppay.reset();
        boppay.setRec(rec);
        boppay.setAmdRec(amdRec);
        boppay.setPtsList(transactionServiceSet.getPtsList());
        boppay.setCbsMap(transactionServiceSet.getCbsMap());
        boppay.setSetFelList(transactionServiceSet.getSetmodVo().getSetfeg().getSetfel());
        boppay.setSetFolList(transactionServiceSet.getSetmodVo().getSetfog().getSetfol());
        boppay.setPtydet(transactionServiceSet.getSetmodVo().getPtydet());
        boppay.setSetgll(transactionServiceSet.getSetmodVo().getSetglg().getSetgll());
        boppay.setTransName(baseTransactionVo.getTransName());
//        CommetItems commetItems = buildCommetItems(baseTransactionVo);
//        boppay.setCommetItems(commetItems);
        return boppay;
    }

}
