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.camt05400108.MXCamt05400108Creator;
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 Camt05400108Test {
    @Test
    public void testCamt05400108() {
        MXCamt05400108Creator mxCamt05400108Creator = new MXCamt05400108Creator("camt.054.001.08");
        // 头部信息
        mxCamt05400108Creator.setSenderBic("PSBCCNBJ");
        mxCamt05400108Creator.setSenderNm("zs");
        mxCamt05400108Creator.setReceiverBic("PSBCCNBJ");
        mxCamt05400108Creator.setReceiverNm("lisi");
        mxCamt05400108Creator.setBizMsgIdr("1111111");
        mxCamt05400108Creator.setMsgDefIdr("sadasdd");
        mxCamt05400108Creator.setBizSvc("swift.cbprplus.02");
        mxCamt05400108Creator.setCreDt(new XmlDate());

        // 账户通知唯一标识
        mxCamt05400108Creator.setId("123456");
        // 账号信息
        Account2 acct = new Account2();
        IdentificationAcc id = new IdentificationAcc();
        id.setIban("BE54988858148300");
        acct.setId(id);
        acct.setCcy("USD");
        mxCamt05400108Creator.setAcct(acct);
        // 对账单细目
        List<Ntry2> ntryList = new ArrayList<>();
        Ntry2 ntry = new Ntry2();
        // 参考信息
        ntry.setNtryRef("1222222");
        // 金额
        Amt amt = new Amt();
        amt.setValue(new BigDecimal("3.4"));
        amt.setCcy("CNY");
        ntry.setAmt(amt);
        // 借贷标记
        ntry.setCdtDbtInd("CRDT");
        // 账户条目状态
        Sts sts = new Sts();
        sts.setCd("a");
        ntry.setSts(sts);
        // 预定日期
        Dt dt = new Dt();
        dt.setDtTm(new XmlDate());
        ntry.setBookgDt(dt);
        // 起息日
        Dt valDate = new Dt();
        valDate.setDt(new Date());
        // valDate.setDtTm(new XmlDate());
        ntry.setValDt(valDate);
        // 银行交易代码信息
        BkTxCd bkTxCd = new BkTxCd();
        Prtry prtry = new Prtry();
        // 专有形式代码
        prtry.setCd("11");
        // 分配上述标识的对象
        prtry.setIssr("2222");
        bkTxCd.setPrtry(prtry);
        ntry.setBkTxCd(bkTxCd);

        ntryList.add(ntry);
        mxCamt05400108Creator.setNtry(ntryList);

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