package com.brilliance.isc.swift.objmtconvert.model.mt2xx;

import com.brilliance.isc.swift.objmtconvert.annotation.FieldDescription;
import com.brilliance.isc.swift.objmtconvert.annotation.Status;
import com.brilliance.isc.swift.objmtconvert.annotation.TagName;
import com.brilliance.isc.swift.objmtconvert.annotation.TagRegex;
import com.brilliance.isc.swift.objmtconvert.model.AbsMTCreator;
import com.brilliance.isc.swift.objmtconvert.model.AbsTagCreate;
import com.brilliance.isc.swift.objmtconvert.model.commontag.ActnoBicAdrTagXXX;
import com.brilliance.isc.swift.objmtconvert.model.mt2xx.mt2XXAbsCreator.MT204AbsCreator;
import com.brilliance.isc.swift.objmtconvert.model.mt2xx.tag.tag204.*;
import com.brilliance.isc.swift.objmtconvert.result.MtResult;

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

/**
 * @Description：
 * @Author：夏猛
 * @CreateTime：2023/2/27 9:19
 **/
public class MT204Creator extends AbsMTCreator {

    //20
    @Status("M")
    @TagName("20")
    @FieldDescription("Transaction Reference Number")
    @TagRegex("16x")
    private String transactionReferenceNumberA;

    //19
    @Status("M")
    @TagName("19")
    @FieldDescription("Sum of Amounts")
    @TagRegex("17d")
    private BigDecimal sumofAmounts;

    //30
    @Status("M")
    @TagName("30")
    @FieldDescription("Value Date")
    @TagRegex("6!n")
    private String valueDate;

    //57a
    @Status("O")
    @TagName({"57A","57B","57D"})
    @FieldDescription("Account With Institution")
    @TagRegex({"[/1!a][/34x]<crlf>4!a2!a2!c[3!c]","[/1!a][/34x]<crlf>[35x]","[/1!a][/34x]<crlf>4*35x"})
    private ActnoBicAdrTagXXX accountWithInstitution;

    //58a
    @Status("O")
    @TagName({"58A","58D"})
    @FieldDescription("Beneficiary Institution")
    @TagRegex({"[/1!a][/34x]<crlf>4!a2!a2!c[3!c]","[/1!a][/34x]<crlf>4*35x"})
    private ActnoBicAdrTagXXX beneficiaryInstitution;

    //72
    @Status("O")
    @TagName("72")
    @FieldDescription("Sender to Receiver Information")
    @TagRegex("6*35x")
    private String sendertoReceiverInformationA;

    //循环集合
    private List<MT204AbsCreator> cycleDomain;

    public String getTransactionReferenceNumberA() {
        return transactionReferenceNumberA;
    }

    public void setTransactionReferenceNumberA(String transactionReferenceNumberA) {
        this.transactionReferenceNumberA = transactionReferenceNumberA;
    }

    public BigDecimal getSumofAmounts() {
        return sumofAmounts;
    }

    public void setSumofAmounts(BigDecimal sumofAmounts) {
        this.sumofAmounts = sumofAmounts;
    }

    public String getValueDate() {
        return valueDate;
    }

    public void setValueDate(String valueDate) {
        this.valueDate = valueDate;
    }

    public ActnoBicAdrTagXXX getAccountWithInstitution() {
        return accountWithInstitution;
    }

    public void setAccountWithInstitution(ActnoBicAdrTagXXX accountWithInstitution) {
        this.accountWithInstitution = accountWithInstitution;
    }

    public ActnoBicAdrTagXXX getBeneficiaryInstitution() {
        return beneficiaryInstitution;
    }

    public void setBeneficiaryInstitution(ActnoBicAdrTagXXX beneficiaryInstitution) {
        this.beneficiaryInstitution = beneficiaryInstitution;
    }

    public String getSendertoReceiverInformationA() {
        return sendertoReceiverInformationA;
    }

    public void setSendertoReceiverInformationA(String sendertoReceiverInformationA) {
        this.sendertoReceiverInformationA = sendertoReceiverInformationA;
    }

    public List getCycleDomain() {
        return cycleDomain;
    }

    public void setCycleDomain(List cycleDomain) {
        this.cycleDomain = cycleDomain;
    }
    public void setCycleDomain(LinkedList cycleDomain) {
        this.cycleDomain = cycleDomain;
    }


    public MT204Creator(String msgType) {
        super(msgType);
    }

    public MT204Creator() {
        super();
    }

    /**
     * 需要编写组装报文逻辑，调用set方法即可
     *
     * @return
     */
    public void pack() {
       // MtResult mtResult = new MtResult();
        List<AbsTagCreate> tagCreateList=new ArrayList<>();
        try {
            tagCreateList.add(new TagA20Creator(this));
            tagCreateList.add(new Tag19Creator(this));
            tagCreateList.add(new Tag30Creator(this));
            tagCreateList.add(new Tag57aCreator(this));
            tagCreateList.add(new Tag58aCreator(this));
            tagCreateList.add(new TagA72Creator(this));
            tagCreateList.add(new TagCycleCreator(this));
            dealTags(tagCreateList);

            mtResult.setMessage(abstractMT.message());
        } catch (Exception e) {
            e.printStackTrace();
            mtResult.setSuccess(false);
            mtResult.addDescription(e.getLocalizedMessage());
        }

       // return mtResult;
    }

    public MtResult unpack() {
        return null;
    }

}