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

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.commontag.DcDateCurAmtTagXXX;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag754.*;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag754.Tag71DCreator;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag754.Tag72ZCreator;
import com.brilliance.isc.swift.objmtconvert.result.MtResult;
import lombok.Data;
import lombok.With;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gaosheng
 * @date 2023/3/2
 */
@Data
public class MT754Creator extends AbsMTCreator {

    //20
    @Status("M")
    @TagName("20")
    @FieldDescription("Sender's Reference")
    @TagRegex("16x")
    private String sendersReference;

    //21
    @Status("M")
    @TagName("21")
    @FieldDescription("Related Reference")
    @TagRegex("16x")
    private String relatedReference;

    //32a
    @Status("M")
    @TagName({"32A","32B"})
    @FieldDescription("Principal Amount Paid/Accepted/Negotiated")
    @TagRegex({"6!n3!a15d","3!a15d"})
    private DcDateCurAmtTagXXX principalAmountPaidAN;

    //33B
    @Status("O")
    @TagName("33B")
    @FieldDescription("Additional Amounts")
    @TagRegex("3!a15d")
    private DcDateCurAmtTagXXX additionalAmounts;

    //71D
    @Status("O")
    @TagName("71D")
    @FieldDescription("Charges Deducted")
    @TagRegex("6*35z")
    private String chargesDeducted;

    //73A
    @Status("O")
    @TagName("73A")
    @FieldDescription("Charges Added")
    @TagRegex("6*35z")
    private String chargesAdded;

    //34a
    @Status("M")
    @TagName({"34A","34B"})
    @FieldDescription("Total Amount Claimed")
    @TagRegex({"6!n3!a15d","3!a15d"})
    private DcDateCurAmtTagXXX totalAmountClaimed;

    //53a
    @Status("O")
    @TagName({"53A","53B","53D"})
    @FieldDescription("Reimbursing Bank")
    @TagRegex({"[/1!a][/34x]<crlf>4!a2!a2!c[3!c]","[/1!a][/34x]<crlf>[35x]","[/1!a][/34x]<crlf>4*35x"})
    private ActnoBicAdrTagXXX reimbursingBank;

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

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

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

    //77
    @Status("O")
    @TagName("77")
    @FieldDescription("Narrative")
    @TagRegex("20*35z")
    private String narrative;

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

    public MT754Creator() {
        super("754");
    }

    /**
     * 需要编写组装报文逻辑，调用set方法即可
     *
     * @return
     */
    public void pack() {
        // MtResult mtResult = new MtResult();
        List<AbsTagCreate> tagCreateList = new ArrayList<>();
        try {
            tagCreateList.add(new Tag20Creator(this));
            tagCreateList.add(new Tag21Creator(this));
            tagCreateList.add(new Tag32aCreator(this));
            tagCreateList.add(new Tag33BCreator(this));
            tagCreateList.add(new Tag71DCreator(this));
            tagCreateList.add(new Tag73ACreator(this));
            tagCreateList.add(new Tag34aCreator(this));
            tagCreateList.add(new Tag53aCreator(this));
            tagCreateList.add(new Tag57aCreator(this));
            tagCreateList.add(new Tag58aCreator(this));
            tagCreateList.add(new Tag72ZCreator(this));
            tagCreateList.add(new Tag77Creator(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;
    }
}
