package com.brilliance.isc.common.addbcb;

import com.brilliance.isc.common.component.PtsptaToolComponent;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.register.document.IDocumentRegister;
import com.brilliance.isc.common.trndoc.service.TrndocService;
import com.brilliance.isc.common.trndoc.vo.TrndocVo;
import com.brilliance.isc.common.util.StringUtils;
import com.brilliance.isc.constant.PartyNames;
import com.brilliance.isc.vo.lg.GidBizInfoVo;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AddBcbDocumentRegister implements IDocumentRegister {

    private final String GIDRECPATH = "GIDGRP\\REC";

    private final String LIDRECPATH = "LIDGRP\\REC";

    public static final String ADDBCB = "ADDBCBL1";

    public static final String DOC_ADDBCB = "ADDBCB1";


    @Autowired
    private PtsptaToolComponent ptsptaToolComponent;

    @Autowired
    private TrndocService trndocService;

    @Override
    public void registerDocument(TrndocVo trndoc) {
        String frame = SettleContext.getTransName();
        String bcb = "";
        if (MdaUtils.compareTo(frame, "GITOPN") == 0 || MdaUtils.compareTo(frame, "GITPOP") == 0 || MdaUtils.compareTo(frame, "GITODZ") == 0) {

            bcb = "保函开立备查表";
        }
        if (MdaUtils.compareTo(frame, "GITAME") == 0 || MdaUtils.compareTo(frame, "GITPAM") == 0) {
            bcb = "保函修改备查表";
        }
        if (MdaUtils.compareTo(frame, "LITROG") == 0) {
            bcb = "中国光大银行开立提货担保审批暨备查表";
        }
        if (MdaUtils.compareTo(frame, "GITOPN") == 0 || MdaUtils.compareTo(frame, "GITPOP") == 0 || MdaUtils.compareTo(frame, "GITAME") == 0 || MdaUtils.compareTo(frame, "GITPAM") == 0 || MdaUtils.compareTo(frame, "GITODZ") == 0) {
            /**
             if $frame == "GITOPN" or $frame == "GITAME" then
             **/
            GidBizInfoVo rec = (GidBizInfoVo)trndoc.getRec();
            if(StringUtils.isEmpty(rec.getHndtyp()) || !"OT".equals(rec.getHndtyp())){
                if (ptsptaToolComponent.ptsIsRolSet(trndoc.getPtsptas(), PartyNames.APL)) {
                    trndocService.defDocEot(trndoc, "TRN", "ADV2", ADDBCB, "LET", 0, ptsptaToolComponent.getPtaInrByRol(trndoc.getPtsptas(), "APL"), GIDRECPATH, bcb, "OWN", "");
                }
            }else{
                if (ptsptaToolComponent.ptsIsRolSet(trndoc.getPtsptas(), PartyNames.CTR)) {
                    trndocService.defDocEot(trndoc, "TRN", "ADV2", ADDBCB, "LET", 0, ptsptaToolComponent.getPtaInrByRol(trndoc.getPtsptas(), "CTR"), GIDRECPATH, bcb, "OWN", "");
                }
            }
        }
        if (MdaUtils.compareTo(frame, "LITROG") == 0) {
            if (ptsptaToolComponent.ptsIsRolSet(trndoc.getPtsptas(), PartyNames.APL)) {
                trndocService.defDocEot(trndoc, "TRN", "ADV2", ADDBCB, "LET", 0, ptsptaToolComponent.getPtaInrByRol(trndoc.getPtsptas(), "APL"), LIDRECPATH, bcb, "OWN", "");
            }
        }
    }
}
