package com.brilliance.isc.json2mx.pacs00800108;

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.*;
import com.brilliance.isc.swift.objmtconvert.model.mx.pacs00800108.MXPacs00800108Creator;
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
 * pacs00800108(MT103)
 */
public class Pacs00800108Test {

    @Test
    public void test_Pacs008() {

        MXPacs00800108Creator mxPacs00800108Creator = new MXPacs00800108Creator("pacs.008.001.08");

        mxPacs00800108Creator.setSenderBic("PSBCCNBJ");

        mxPacs00800108Creator.setSenderNm("zs");

        mxPacs00800108Creator.setReceiverBic("PSBCCNBJ");

        mxPacs00800108Creator.setReceiverNm("lisi");

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

        mxPacs00800108Creator.setEndToEndId("sadas");

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

        mxPacs00800108Creator.setCreDt(new XmlDate());

        SttlmInf sttlmInf = new SttlmInf();
        mxPacs00800108Creator.setSttlmInf(sttlmInf);
        sttlmInf.setSttlmMtd("COVE");
        Account sttlmAcct = new Account();
        sttlmInf.setSttlmAcct(sttlmAcct);
        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("BBAN");
        othr.setSchmeNm(schmeNm);
        Tp tp = new Tp();
        sttlmAcct.setTp(tp);
        tp.setCd("CACC");
        Agent instgRmbrsmntAgt = new Agent();
        sttlmInf.setInstgRmbrsmntAgt(instgRmbrsmntAgt);
        FinInstnId finInstnId = new FinInstnId();
        PstlAdr pstlAdr = new PstlAdr();
        finInstnId.setBicfi("PSBCCNBJ");
        finInstnId.setNm("zhaoliu");
        finInstnId.setLei("12345678901234567811");
        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);
        instgRmbrsmntAgt.setFinInstnId(finInstnId);
        Account instgRmbrsmntAgtAcct = new Account();
        sttlmInf.setInstdRmbrsmntAgtAcct(instgRmbrsmntAgtAcct);
        IdentificationAcc identificationAcc2 = new IdentificationAcc();
        instgRmbrsmntAgtAcct.setId(identificationAcc2);
        identificationAcc2.setIban("AA22321232132132131");
        sttlmInf.setInstdRmbrsmntAgt(instgRmbrsmntAgt);
        sttlmInf.setInstdRmbrsmntAgtAcct(instgRmbrsmntAgtAcct);
        sttlmInf.setThrdRmbrsmntAgt(instgRmbrsmntAgt);
        sttlmInf.setThrdRmbrsmntAgtAcct(instgRmbrsmntAgtAcct);

        mxPacs00800108Creator.setClrChanl("BOOK");

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

        LclInstrm lclInstrm = new LclInstrm();
        lclInstrm.setCd("DDMC");
        mxPacs00800108Creator.setLclInstrm(lclInstrm);

        CtgyPurp ctgyPurp = new CtgyPurp();
        ctgyPurp.setCd("CORT");
        mxPacs00800108Creator.setCtgyPurp(ctgyPurp);

        Amt intrBkSttlmAmt = new Amt();
        intrBkSttlmAmt.setValue(new BigDecimal("111.1"));
        intrBkSttlmAmt.setCcy("USD");
        mxPacs00800108Creator.setIntrBkSttlmAmt(intrBkSttlmAmt);

        mxPacs00800108Creator.setIntrBkSttlmDt(new Date());

        mxPacs00800108Creator.setInstdAmt(intrBkSttlmAmt);

        mxPacs00800108Creator.setXchgRate(new BigDecimal("1.0"));

        mxPacs00800108Creator.setChrgBr("CRED");

        ChrgsInf chrgsInf = new ChrgsInf();
        chrgsInf.setAmt(intrBkSttlmAmt);
        chrgsInf.setAgt(instgRmbrsmntAgt);

        mxPacs00800108Creator.setPrvsInstgAgt1(instgRmbrsmntAgt);
        mxPacs00800108Creator.setPrvsInstgAgt1Acct(sttlmAcct);
        mxPacs00800108Creator.setPrvsInstgAgt2(instgRmbrsmntAgt);
        mxPacs00800108Creator.setPrvsInstgAgt2Acct(sttlmAcct);
        mxPacs00800108Creator.setPrvsInstgAgt3(instgRmbrsmntAgt);
        mxPacs00800108Creator.setPrvsInstgAgt3Acct(sttlmAcct);

        mxPacs00800108Creator.setIntrmyAgt1(instgRmbrsmntAgt);
        mxPacs00800108Creator.setIntrmyAgt1Acct(sttlmAcct);
        mxPacs00800108Creator.setIntrmyAgt2(instgRmbrsmntAgt);
        mxPacs00800108Creator.setIntrmyAgt2Acct(sttlmAcct);
        mxPacs00800108Creator.setIntrmyAgt3(instgRmbrsmntAgt);
        mxPacs00800108Creator.setIntrmyAgt3Acct(sttlmAcct);

        Party dbtr = new Party();
        dbtr.setNm("tianqi");
        dbtr.setPstlAdr(pstlAdr);
        IdentificationPty identificationPty = new IdentificationPty();
        OrgId orgId = new OrgId();
        identificationPty.setOrgId(orgId);
        orgId.setLei("12345678901234567811");
        orgId.setAnyBIC("PSBCCNBJ");
        List<Othr> othrList = new ArrayList<>();
        othrList.add(othr);
        orgId.setOthr(othrList);
        dbtr.setId(identificationPty);
        mxPacs00800108Creator.setDbtr(dbtr);

        mxPacs00800108Creator.setDbtrAcct(instgRmbrsmntAgtAcct);
        mxPacs00800108Creator.setDbtrAgt(instgRmbrsmntAgt);
        mxPacs00800108Creator.setDbtrAgtAcct(instgRmbrsmntAgtAcct);
        mxPacs00800108Creator.setCdtr(dbtr);
        mxPacs00800108Creator.setCdtrAcct(instgRmbrsmntAgtAcct);
        mxPacs00800108Creator.setCdtrAgt(instgRmbrsmntAgt);
        mxPacs00800108Creator.setCdtrAgtAcct(instgRmbrsmntAgtAcct);

        List<InstrForCdtrAgt> instrForCdtrAgtList = new ArrayList<>();
        InstrForCdtrAgt instrForCdtrAgt = new InstrForCdtrAgt();
        instrForCdtrAgt.setInstrInf("ccc");
        instrForCdtrAgt.setCd("CHQB");
        instrForCdtrAgtList.add(instrForCdtrAgt);
        instrForCdtrAgtList.add(instrForCdtrAgt);
        mxPacs00800108Creator.setInstrForCdtrAgt(instrForCdtrAgtList);

        List<InstrForNxtAgt> instrForNxtAgtList = new ArrayList<>();
        InstrForNxtAgt instrForNxtAgt = new InstrForNxtAgt();
        instrForNxtAgt.setInstrInf("fff");
        instrForNxtAgt.setCd("PHOA");
        instrForNxtAgtList.add(instrForNxtAgt);
        instrForNxtAgtList.add(instrForNxtAgt);
        mxPacs00800108Creator.setInstrForNxtAgt(instrForNxtAgtList);

        Purp purp = new Purp();
        purp.setCd("ACCT");
        mxPacs00800108Creator.setPurp(purp);

        List<String> ustrdList = new ArrayList<>();
        ustrdList.add("111111");
        mxPacs00800108Creator.setUstrd(ustrdList);

        List<String> infList = new ArrayList<>();
        infList.add("22222");
        mxPacs00800108Creator.setInf(infList);

        mxPacs00800108Creator.setNbOfTxs("1");

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

    @Test
    public void test_Pacs008_2() {

        MXPacs00800108Creator mxPacs00800108Creator = new MXPacs00800108Creator("pacs.008.001.08");

        mxPacs00800108Creator.setSenderBic("TSPABEB0XXX");

        mxPacs00800108Creator.setReceiverBic("TSPBBEB0XXX");

        mxPacs00800108Creator.setBizMsgIdr("MID/7701.0/2cb05");

        mxPacs00800108Creator.setMsgDefIdr("pacs.008.001.08");

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

        mxPacs00800108Creator.setCreDt(new XmlDate());

        mxPacs00800108Creator.setNbOfTxs("1");

        SttlmInf sttlmInf = new SttlmInf();
        sttlmInf.setSttlmMtd("INGA");
        mxPacs00800108Creator.setSttlmInf(sttlmInf);

        mxPacs00800108Creator.setEndToEndId("E2E/7701.0/2cb05");

        mxPacs00800108Creator.setUetr("eb4e7f8d-a762-4428-bd41-0c6ae44e7e25");

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

        Amt intrBkSttlmAmt = new Amt();
        intrBkSttlmAmt.setCcy("USD");
        intrBkSttlmAmt.setValue(new BigDecimal("12340.0"));
        mxPacs00800108Creator.setIntrBkSttlmAmt(intrBkSttlmAmt);

        mxPacs00800108Creator.setIntrBkSttlmDt(new Date());

        Amt instdAmt = new Amt();
        instdAmt.setCcy("USD");
        instdAmt.setValue(new BigDecimal("12345.0"));
        mxPacs00800108Creator.setInstdAmt(instdAmt);

        mxPacs00800108Creator.setChrgBr("SHAR");

        ChrgsInf chrgsInf = new ChrgsInf();
        Amt amt = new Amt();
        amt.setCcy("USD");
        amt.setValue(new BigDecimal("5.0"));
        chrgsInf.setAmt(amt);
        Agent agt = new Agent();
        FinInstnId finInstnId = new FinInstnId();
        finInstnId.setBicfi("TSPABEB0XXX");
        agt.setFinInstnId(finInstnId);
        chrgsInf.setAgt(agt);
        List<ChrgsInf> chrgsInfList = new ArrayList<>();
        chrgsInfList.add(chrgsInf);
        mxPacs00800108Creator.setChrgsInf(chrgsInfList);

        Party party = new Party();
        party.setNm("Treasury Management Corp");
        IdentificationPty id = new IdentificationPty();
        OrgId orgId = new OrgId();
        orgId.setAnyBIC("TSPLBEB0XXX");
        id.setOrgId(orgId);
        party.setId(id);
        mxPacs00800108Creator.setDbtr(party);

        Account dbtrAcct = new Account();
        IdentificationAcc id2 = new IdentificationAcc();
        id2.setIban("BE54988858148300");
        dbtrAcct.setId(id2);
        mxPacs00800108Creator.setDbtrAcct(dbtrAcct);

        Agent dbtrAgt = new Agent();
        FinInstnId finInstnId1 = new FinInstnId();
        finInstnId1.setBicfi("TSPABEB0XXX");
        dbtrAgt.setFinInstnId(finInstnId1);
        mxPacs00800108Creator.setDbtrAgt(dbtrAgt);

        Account dbtrAgtAcct = new Account();
        IdentificationAcc id3 = new IdentificationAcc();
        id3.setIban("BE86199467768950");
        dbtrAgtAcct.setId(id3);
        mxPacs00800108Creator.setDbtrAgtAcct(dbtrAgtAcct);

        Agent cdtrAgt = new Agent();
        FinInstnId finInstnId2 = new FinInstnId();
        finInstnId2.setBicfi("PSBCCNBJXXX");
        cdtrAgt.setFinInstnId(finInstnId2);
        mxPacs00800108Creator.setCdtrAgt(cdtrAgt);

        Account cdtrAgtAcct = new Account();
        IdentificationAcc id4 = new IdentificationAcc();
        Othr othr = new Othr();
        othr.setId("FT12234444");
        id4.setOthr(othr);
        cdtrAgtAcct.setId(id4);
        mxPacs00800108Creator.setCdtrAgtAcct(cdtrAgtAcct);

        Party cdtr = new Party();
        cdtr.setNm("Structured Fund Management BE");
        PstlAdr pstlAdr = new PstlAdr();
        pstlAdr.setStrtNm("Cours St Michel");
        pstlAdr.setBldgNb("5");
        pstlAdr.setPstBx("18");
        pstlAdr.setPstCd("1040");
        pstlAdr.setTwnNm("Brussels");
        pstlAdr.setCtry("BE");
        cdtr.setPstlAdr(pstlAdr);
        mxPacs00800108Creator.setCdtr(cdtr);

        Account cdtrAcct = new Account();
        IdentificationAcc id5 = new IdentificationAcc();
        id5.setIban("BE54988858148300");
        cdtrAcct.setId(id5);
        cdtrAcct.setCcy("EUR");
        mxPacs00800108Creator.setCdtrAcct(cdtrAcct);

        mxPacs00800108Creator.setCd("CINV");
        mxPacs00800108Creator.setNb("A078900012023");
        Amt duePyblAmt = new Amt();
        duePyblAmt.setCcy("EUR");
        duePyblAmt.setValue(new BigDecimal("1000.0"));
        mxPacs00800108Creator.setDuePyblAmt(duePyblAmt);

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


}
