package com.brilliance.isc.json2mx.pacs00400109;

import com.brilliance.isc.swift.objmtconvert.ext.XmlDate;
import com.brilliance.isc.swift.objmtconvert.manager.CreatorManager;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.Account;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.Agent;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.Amt;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.Cdtr;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.ChrgsInf;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.Dbtr;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.FinInstnId;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.IdentificationAcc;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.IdentificationPty;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.OrgId;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.OrgnlGrpInf;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.Othr;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.Party;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.PstlAdr;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.SchmeNm;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.SttlmTmIndctn;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.SvcLvl;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.Tp;
import com.brilliance.isc.swift.objmtconvert.model.mx.pacs00400109.MXPacs00400109Creator;
import com.brilliance.isc.swift.objmtconvert.result.MxResult;
import org.junit.Test;

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

/**
 * @author zh
 * @create 2023-04-20-9:48
 * pacs00400109(103RETN,202RETN)
 */
public class Pacs00400109Test {

    @Test
    public void test_Pacs004(){
        MXPacs00400109Creator mxPacs00400109Creator = new MXPacs00400109Creator("pacs.004.001.09");

        mxPacs00400109Creator.setSenderBic("PSBCCNBJ");

        mxPacs00400109Creator.setSenderNm("zs");

        mxPacs00400109Creator.setReceiverBic("PSBCCNBJ");

        mxPacs00400109Creator.setReceiverNm("lisi");

//        bizMsgIdr为系统自动生成，如果需要手动给值也可
//        String bizMsgIdr = "1111111";
//        mxPacs00900108COVCreator.setBizMsgIdr(bizMsgIdr);
        mxPacs00400109Creator.setMsgDefIdr("sadasdd");

        mxPacs00400109Creator.setBizSvc("swift.cbprplus.02");

        mxPacs00400109Creator.setCreDt(new XmlDate());

        mxPacs00400109Creator.setMsgId("dasdasd");

        mxPacs00400109Creator.setCreDtTm(new XmlDate());

        mxPacs00400109Creator.setSttlmMtd("INDA");

        Account sttlmAcct = new Account();
        sttlmAcct.setNm("wangwu");
        sttlmAcct.setCcy("USD");
        IdentificationAcc identificationAcc = new IdentificationAcc();
        sttlmAcct.setId(identificationAcc);
        Othr othr = new Othr();
        identificationAcc.setOthr(othr);
        othr.setId("adadsds");
        SchmeNm schmeNm = new SchmeNm();
        schmeNm.setCd("ABCD");
        othr.setSchmeNm(schmeNm);
        Tp tp = new Tp();
        tp.setCd("CACC");
        sttlmAcct.setTp(tp);
        mxPacs00400109Creator.setSttlmAcct(sttlmAcct);

        mxPacs00400109Creator.setRtrId("zzz");

        OrgnlGrpInf orgnlGrpInf = new OrgnlGrpInf();
        orgnlGrpInf.setOrgnlMsgId("31231");
        orgnlGrpInf.setOrgnlCreDtTm(new XmlDate());
        orgnlGrpInf.setOrgnlMsgNmId("bank");
        mxPacs00400109Creator.setOrgnlGrpInf(orgnlGrpInf);

        mxPacs00400109Creator.setOrgnlInstrId("sddffas");

        mxPacs00400109Creator.setOrgnlEndToEndId("sddffas");

        mxPacs00400109Creator.setOrgnlUETR("8a562c67-ca16-48ba-b074-65581be6f001");

        mxPacs00400109Creator.setOrgnlClrSysRef("122331313");

        Amt orgnlIntrBkSttlmAmt = new Amt();
        orgnlIntrBkSttlmAmt.setValue(new BigDecimal("111.1"));
        orgnlIntrBkSttlmAmt.setCcy("USD");
        mxPacs00400109Creator.setOrgnlIntrBkSttlmAmt(orgnlIntrBkSttlmAmt);

        mxPacs00400109Creator.setOrgnlIntrBkSttlmDt(new Date());

        mxPacs00400109Creator.setRtrdIntrBkSttlmAmt(orgnlIntrBkSttlmAmt);

        mxPacs00400109Creator.setRtrdInstdAmt(orgnlIntrBkSttlmAmt);

        mxPacs00400109Creator.setIntrBkSttlmDt(new Date());

        SttlmTmIndctn sttlmTmIndctn = new SttlmTmIndctn();
        sttlmTmIndctn.setCdtDtTm(new XmlDate());
        sttlmTmIndctn.setDbtDtTm(new XmlDate());
        mxPacs00400109Creator.setSttlmTmIndctn(sttlmTmIndctn);

        mxPacs00400109Creator.setRtrdInstdAmt(orgnlIntrBkSttlmAmt);

        mxPacs00400109Creator.setExchgRate(new BigDecimal("1.1"));

        mxPacs00400109Creator.setChrgBr("CRED");

        List<ChrgsInf> chrgsInfList = new ArrayList<>();
        ChrgsInf chrgsInf = new ChrgsInf();
        chrgsInf.setAmt(orgnlIntrBkSttlmAmt);
        Agent agt = new Agent();
        FinInstnId finInstnId = new FinInstnId();
        PstlAdr pstlAdr = new PstlAdr();
        finInstnId.setBicfi("PSBCCNBJ");
        finInstnId.setNm("zhaoliu");
        finInstnId.setLei("11111111111111111111");
        List<String> list = new ArrayList<>();
        list.add("BIODATA GMBH");
        list.add("HOCHSTRASSE, 27");
        pstlAdr.setCtry("CN");
        pstlAdr.setBldgNb("111");
        pstlAdr.setBldgNm("ti mi");
        pstlAdr.setDept("xiao shan");
        pstlAdr.setCtrySubDvsn("tiger");
        pstlAdr.setDstrctNm("zzz");
        pstlAdr.setFlr("2");
        pstlAdr.setPstBx("40000");
        pstlAdr.setPstCd("103");
        pstlAdr.setRoom("103");
        pstlAdr.setStrtNm("xiao li Street");
        pstlAdr.setTwnLctnNm("xiao xiao");
        pstlAdr.setTwnNm("xiao xiao");
        pstlAdr.setAdrLine(list);
        finInstnId.setPstlAdr(pstlAdr);
        agt.setFinInstnId(finInstnId);
        chrgsInf.setAgt(agt);
        chrgsInfList.add(chrgsInf);
        chrgsInfList.add(chrgsInf);
        mxPacs00400109Creator.setChrgsInf(chrgsInfList);

        Party pty = new Party();
        pty.setNm("tianqi");
        pty.setPstlAdr(pstlAdr);
        IdentificationPty identificationPty = new IdentificationPty();
        OrgId orgId = new OrgId();
        identificationPty.setOrgId(orgId);
        orgId.setLei("11111111111111111111");
        orgId.setAnyBIC("PSBCCNBJ");
        List<Othr> othrList = new ArrayList<>();
        othrList.add(othr);
        orgId.setOthr(othrList);
        pty.setId(identificationPty);
        Dbtr dbtr = new Dbtr();
        dbtr.setPty(pty);
//        dbtr.setAgt(agt);
        mxPacs00400109Creator.setDbtr(dbtr);

        mxPacs00400109Creator.setDbtrAgt(agt);

        mxPacs00400109Creator.setPrvsInstgAgt1(agt);

        mxPacs00400109Creator.setPrvsInstgAgt2(agt);

        mxPacs00400109Creator.setPrvsInstgAgt3(agt);

        mxPacs00400109Creator.setIntrmyAgt1(agt);

        mxPacs00400109Creator.setIntrmyAgt2(agt);

        mxPacs00400109Creator.setIntrmyAgt3(agt);

        mxPacs00400109Creator.setCdtrAgt(agt);

        Cdtr cdtr = new Cdtr();
        cdtr.setPty(pty);
//        cdtr.setAgt(agt);
        mxPacs00400109Creator.setCdtr(cdtr);

        mxPacs00400109Creator.setOrgtr(pty);

        mxPacs00400109Creator.setRsnCd("AC01");

        List<String> addtlInfList = new ArrayList<>();
        addtlInfList.add("111");
        addtlInfList.add("222");
        mxPacs00400109Creator.setAddtlInf(addtlInfList);

        List<SvcLvl> svcLvlList = new ArrayList<>();
        SvcLvl svcLvl = new SvcLvl();
        svcLvl.setCd("SEPA");
        svcLvlList.add(svcLvl);
        mxPacs00400109Creator.setSvcLvl(svcLvlList);

        mxPacs00400109Creator.setNbOfTxs("1");

        MxResult result = (MxResult) CreatorManager.pack(mxPacs00400109Creator);
        if(result.isSuccess())
            System.out.println(result.getMessage());
        else{
            System.out.println(result.getErrorInf());
        }
    }
    @Test
    public void test_Pacs004_2(){
        MXPacs00400109Creator mxPacs00400109Creator = new MXPacs00400109Creator("pacs.004.001.09");

        mxPacs00400109Creator.setSenderBic("CLYDGB2S");

        mxPacs00400109Creator.setReceiverBic("BOFSGB2L");

        mxPacs00400109Creator.setBizMsgIdr("pacs9bizmsgidr01");

        mxPacs00400109Creator.setMsgDefIdr("pacs.009.001.08");

        mxPacs00400109Creator.setBizSvc("swift.cbprplus.cov.01");

        mxPacs00400109Creator.setCreDt(new XmlDate());

        mxPacs00400109Creator.setMsgId("pacs4bizmsgidr03");

        mxPacs00400109Creator.setCreDtTm(new XmlDate());

        mxPacs00400109Creator.setNbOfTxs("1");

        mxPacs00400109Creator.setSttlmMtd("INGA");

        OrgnlGrpInf orgnlGrpInf = new OrgnlGrpInf();
        orgnlGrpInf.setOrgnlMsgId("pacs9bizmsgidr01");
        orgnlGrpInf.setOrgnlMsgNmId("pacs.009.001.08");
        mxPacs00400109Creator.setOrgnlGrpInf(orgnlGrpInf);

        mxPacs00400109Creator.setOrgnlInstrId("pacs9bizmsgidr01");

        mxPacs00400109Creator.setOrgnlEndToEndId("pacs8bizmsgidr01");

        mxPacs00400109Creator.setOrgnlUETR("8a562c67-ca16-48ba-b074-65581be6f001");

        Amt orgnlIntrBkSttlmAmt = new Amt();
        orgnlIntrBkSttlmAmt.setCcy("EUR");
        orgnlIntrBkSttlmAmt.setValue(new BigDecimal("25000"));
        mxPacs00400109Creator.setOrgnlIntrBkSttlmAmt(orgnlIntrBkSttlmAmt);

        mxPacs00400109Creator.setOrgnlIntrBkSttlmDt(new Date());

        Amt rtrdIntrBkSttlmAmt = new Amt();
        rtrdIntrBkSttlmAmt.setCcy("EUR");
        rtrdIntrBkSttlmAmt.setValue(new BigDecimal("25000"));
        mxPacs00400109Creator.setRtrdIntrBkSttlmAmt(rtrdIntrBkSttlmAmt);

        mxPacs00400109Creator.setIntrBkSttlmDt(new Date());

        mxPacs00400109Creator.setChrgBr("SHAR");

        Dbtr dbtr = new Dbtr();
        Agent agt = new Agent();
        FinInstnId finInstnId = new FinInstnId();
        finInstnId.setBicfi("BOFSGB2L");
        agt.setFinInstnId(finInstnId);
        dbtr.setAgt(agt);
        mxPacs00400109Creator.setDbtr(dbtr);

        Cdtr cdtr = new Cdtr();
        Agent agt2 = new Agent();
        FinInstnId finInstnId1 = new FinInstnId();
        finInstnId1.setBicfi("CLYDGB2S");
        agt2.setFinInstnId(finInstnId1);
        cdtr.setAgt(agt2);
        mxPacs00400109Creator.setCdtr(cdtr);

        mxPacs00400109Creator.setRsnCd("AGNT");

        MxResult result = (MxResult) CreatorManager.pack(mxPacs00400109Creator);
        if(result.isSuccess())
            System.out.println(result.getMessage());
        else{
            System.out.println(result.getErrorInf());
        }
    }
}
