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.mt7xx.tag.tag759.*;
import com.brilliance.isc.swift.objmtconvert.result.MtResult;
import lombok.Data;

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

/**
 * @author wuzhe
 * @date 2023/3/2
 */
@Data
public class MT759Creator extends AbsMTCreator {
    @Status("M")
    @TagName("27")
    @FieldDescription("Sequence of Total")
    @TagRegex("1!n/1!n")
    //27
    private String sequenceofTotal;
    @Status("M")
    @TagName("20")
    @FieldDescription("Transaction Reference Number")
    @TagRegex("16x")
    private String transactionReferenceNumber;
    //20
    @Status("O")
    @TagName("21")
    @FieldDescription("Related Reference Number")
    @TagRegex("16x")
    //21
    private String relatedReferenceNumber;
    @Status("M")
    @TagName("22D")
    @FieldDescription("Form of Undertaking")
    @TagRegex("4!c")
    //22D
    private String formofUndertaking;
    @Status("O")
    @TagName("23")
    @FieldDescription("Undertaking Number")
    @TagRegex("16x")
    //23
    private String undertakingNumber;
    @Status("O")
    @TagName({"52A","52D"})
    @FieldDescription("Issuer")
    @TagRegex({"[/1!a][/34x]<crlf>4!a2!a2!c[3!c]","[/1!a][/34x]<crlf>4*35x"})
    //52a
    private ActnoBicAdrTagXXX issuer;
    @Status("M")
    @TagName("23H")
    @FieldDescription("Function of Message")
    @TagRegex("8!c")
    //23H
    private String functionofMessage;
    @Status("M")
    @TagName("45D")
    @FieldDescription("Narrative")
    @TagRegex("1200*65z")
    //45D
    private String narrative;
    @Status("O")
    @TagName("23X")
    @FieldDescription("File Identification")
    @TagRegex("4!c/65x")
    //23X
    private String fileIdentification;

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

    public MT759Creator() {
        super("759");
    }

    /**
     * 需要编写组装报文逻辑，调用set方法即可
     *
     * @return
     */
    public void pack() {
        //  MtResult mtResult = new MtResult();
        List<AbsTagCreate> tagCreateList = new ArrayList<>();
        try {
            tagCreateList.add(new Tag27Creator(this));
            tagCreateList.add(new Tag20Creator(this));
            tagCreateList.add(new Tag21Creator(this));
            tagCreateList.add(new Tag22DCreator(this));
            tagCreateList.add(new Tag23Creator(this));
            tagCreateList.add(new Tag52aCreator(this));
            tagCreateList.add(new Tag23HCreator(this));
            tagCreateList.add(new Tag45DCreator(this));
            tagCreateList.add(new Tag23XCreator(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;
    }

}

