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

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.mt4xx.mt4XXAbsCreator.MT416AbsCreator;
import com.brilliance.isc.swift.objmtconvert.model.mt4xx.tag.tag416.*;
import com.brilliance.isc.swift.objmtconvert.result.MtResult;

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

/**
 * @author hw
 * @create 2024-07-05-13:42
 */
public class MT416Creator extends AbsMTCreator {

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

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

    @Status("O")
    @TagName("23E")
    @FieldDescription("Advice Type")
    @TagRegex("4!c[/30x]")
    private String adviceType;

    @Status("O")
    @TagName("51A")
    @FieldDescription("Sending Institution")
    @TagRegex("[/1!a][/34x]<crlf>4!a2!a2!c[3!c]")
    private ActnoBicAdrTagXXX sendingInstitution;

    @Status("O")
    @TagName("53a")
    @FieldDescription("Sender's Correspondent")
    private ActnoBicAdrTagXXX senderCorrespondent;

    @Status("O")
    @TagName("71F")
    @FieldDescription("Sender's Charges")
    @TagRegex("3!a15d")
    private String senderCharges;

    @Status("O")
    @TagName("77A")
    @FieldDescription("Reason for Non-Payment/Non-Acceptance")
    @TagRegex("20*35x")
    private String reason;

    private List<MT416AbsCreator> mt416AbsCreators;

    public String getSenderReference() {
        return senderReference;
    }

    public void setSenderReference(String senderReference) {
        this.senderReference = senderReference;
    }

    public String getRelatedReference() {
        return relatedReference;
    }

    public void setRelatedReference(String relatedReference) {
        this.relatedReference = relatedReference;
    }

    public String getAdviceType() {
        return adviceType;
    }

    public void setAdviceType(String adviceType) {
        this.adviceType = adviceType;
    }

    public ActnoBicAdrTagXXX getSendingInstitution() {
        return sendingInstitution;
    }

    public void setSendingInstitution(ActnoBicAdrTagXXX sendingInstitution) {
        this.sendingInstitution = sendingInstitution;
    }

    public ActnoBicAdrTagXXX getSenderCorrespondent() {
        return senderCorrespondent;
    }

    public void setSenderCorrespondent(ActnoBicAdrTagXXX senderCorrespondent) {
        this.senderCorrespondent = senderCorrespondent;
    }

    public String getSenderCharges() {
        return senderCharges;
    }

    public void setSenderCharges(String senderCharges) {
        this.senderCharges = senderCharges;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

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

    public MT416Creator() {
        super("416");
    }

    public List<MT416AbsCreator> getMt416SequenceBCreatorList() {
        return mt416AbsCreators;
    }

    public void setMt416SequenceBCreatorList(List<MT416AbsCreator> mt416SequenceBCreatorList) {
        this.mt416AbsCreators = mt416SequenceBCreatorList;
    }

    /**
     * 需要编写组装报文逻辑，调用set方法即可
     *
     * @return
     */
    public void pack() {
        List<AbsTagCreate> tagCreateList = new ArrayList<>();
        try {
            tagCreateList.add(new TagCycleCreator(this));
            tagCreateList.add(new Tag20Creator(this));
            tagCreateList.add(new Tag21Creator(this));
            tagCreateList.add(new Tag23EACreator(this));
            tagCreateList.add(new Tag51ACreator(this));
            tagCreateList.add(new Tag53ACreator(this));
            tagCreateList.add(new Tag71FACreator(this));
            tagCreateList.add(new Tag77AACreator(this));
            dealTags(tagCreateList);

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

    public MtResult unpack() {
        return null;
    }
}
