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.camt05300108.MXCamt05300108Creator;
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 Camt05300108Test {
    @Test
    public void testCamt05300108() {
        MXCamt05300108Creator mxCamt05300108Creator = new MXCamt05300108Creator("camt.053.001.08");
        // 头部信息
        mxCamt05300108Creator.setSenderBic("PSBCCNBJ");
        mxCamt05300108Creator.setSenderNm("zs");
        mxCamt05300108Creator.setReceiverBic("PSBCCNBJ");
        mxCamt05300108Creator.setReceiverNm("lisi");
        mxCamt05300108Creator.setBizMsgIdr("1111111");
        mxCamt05300108Creator.setMsgDefIdr("sadasdd");
        mxCamt05300108Creator.setBizSvc("swift.cbprplus.02");
        mxCamt05300108Creator.setCreDt(new XmlDate());

        // 账号信息
        Account2 acct = new Account2();
        IdentificationAcc id = new IdentificationAcc();
        id.setIban("BE54988858148300");
        acct.setId(id);
        acct.setCcy("USD");
        mxCamt05300108Creator.setAcct(acct);

        // 对账单号码
        mxCamt05300108Creator.setLglSeqNb(new BigDecimal("12345.0"));

        // 账户分页信息
        StmtPgntn stmtPgntn = new StmtPgntn();
        stmtPgntn.setLastPgInd(true);
        stmtPgntn.setPgNb("1");
        mxCamt05300108Creator.setStmtPgntn(stmtPgntn);

        // 余额信息
        List<Balance> balList = new ArrayList<>();
        Balance balance = new Balance();
        Amt amt = new Amt();
        amt.setCcy("USD");
        amt.setValue(new BigDecimal("1.2"));
        balance.setAmt(amt);
        BalanceType tp = new BalanceType();
        CdOrPrtry cdOrPrtry = new CdOrPrtry();
        // cdOrPrtry.setPrtry("PurpPrtry");
        cdOrPrtry.setCd("Purp");
        tp.setCdOrPrtry(cdOrPrtry);
        balance.setTp(tp);
        // 借贷标识
        balance.setCdtDbtInd("CRDT");
        // 日期
        Dt dt = new Dt();
        dt.setDt(new Date());
        balance.setDt(dt);
        balList.add(balance);
        mxCamt05300108Creator.setBal(balList);

        // 附加信息
        mxCamt05300108Creator.setAddtlStmtInf("appendInfo");
        MxResult result = (MxResult) CreatorManager.pack(mxCamt05300108Creator);
        if (result.isSuccess()) {
            System.out.println(result.getMessage());
        } else {
            System.out.println(result.getErrorInf());
        }
    }
}
