package com.brilliance.isc.json2mx;

import com.brilliance.isc.swift.objmtconvert.ext.XmlDate;
import com.brilliance.isc.swift.objmtconvert.manager.CreatorManager;
import com.brilliance.isc.swift.objmtconvert.model.mx.camt05600108.MXCamt05600108Creator;
import com.brilliance.isc.swift.objmtconvert.model.mx.common.*;
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;

/**
 * @Description
 * @Author s_guodong
 * @Date 2023/4/23
 */
public class Camt05600108Test {
    @Test
    public void testCamt05600108() {
        MXCamt05600108Creator mxCamt05600108Creator = new MXCamt05600108Creator("camt.056.001.08");
        // 头部信息
        mxCamt05600108Creator.setSenderBic("PSBCCNBJ");
        mxCamt05600108Creator.setSenderNm("zs");
        mxCamt05600108Creator.setReceiverBic("PSBCCNBJ");
        mxCamt05600108Creator.setReceiverNm("lisi");
        mxCamt05600108Creator.setBizMsgIdr("1111111");
        mxCamt05600108Creator.setMsgDefIdr("sadasdd");
        mxCamt05600108Creator.setBizSvc("swift.cbprplus.02");
        mxCamt05600108Creator.setCreDt(new XmlDate());

        // 转让行代理行
        Agent assgnrAgt = new Agent();
        FinInstnId finInstnId = new FinInstnId();
        finInstnId.setBicfi("PSBCCNBJ");
        finInstnId.setLei("11111111111111111111");
        assgnrAgt.setFinInstnId(finInstnId);
        mxCamt05600108Creator.setAssgnrAgt(assgnrAgt);

        // 受让代理行
        Agent assgneAgt = new Agent();
        FinInstnId finInstnId1 = new FinInstnId();
        finInstnId1.setBicfi("PSBCCNBF");
        finInstnId1.setLei("22222222222222222222");
        assgneAgt.setFinInstnId(finInstnId1);
        mxCamt05600108Creator.setAssgneAgt(assgneAgt);

        // 原始消息标识号
        mxCamt05600108Creator.setOrgnlMsgId("678890009098");

        // 原始消息标识名称
        mxCamt05600108Creator.setOrgnlMsgNmId("hhhhhhh");

        // 原始消息创建时间
        mxCamt05600108Creator.setOrgnlCreDtTm(new XmlDate());

        // 原始端到端标识号
        mxCamt05600108Creator.setOrgnlEndToEndId("8888888888888");

        // 原始交易唯一标识
        mxCamt05600108Creator.setOrgnlTxId("999999999");

        // 发报行给收报行的金额
        Amt amt = new Amt();
        amt.setCcy("CNY");
        amt.setValue(new BigDecimal("56.8"));
        mxCamt05600108Creator.setOrgnlIntrBkSttlmAmt(amt);

        // 原始结算日期
        mxCamt05600108Creator.setOrgnlIntrBkSttlmDt(new Date());

        // 取消原因详情
        List<CxlRsnInf> list = new ArrayList<>();
        CxlRsnInf cxlRsnInf = new CxlRsnInf();
        Rsn rsn = new Rsn();
        rsn.setCd("CUTA");
        cxlRsnInf.setRsn(rsn);
        list.add(cxlRsnInf);
        mxCamt05600108Creator.setCxlRsnInf(list);

        // 当事人信息
        Cretr cretr = new Cretr();
        // 参与行信息
        Agent agt = new Agent();
        FinInstnId finInstnId2 = new FinInstnId();
        PstlAdr pstlAdr = new PstlAdr();
        finInstnId2.setBicfi("PSBCCNBJ");
        finInstnId2.setNm("zhaoliu");
        finInstnId2.setLei("12345678901234567811");
        List<String> list1 = new ArrayList<>();
        list1.add("BIODATA GMBH");
        list1.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(list1);
        finInstnId2.setPstlAdr(pstlAdr);
        agt.setFinInstnId(finInstnId);
        cretr.setAgt(agt);
        // 参与方信息
        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");
        dbtr.setId(identificationPty);
        //  cretr.setPty(dbtr);
        mxCamt05600108Creator.setCretr(cretr);

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