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.tag785.Tag20Creator;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag785.Tag21Creator;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag785.Tag23XCreator;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag785.Tag31CCreator;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag785.Tag31ECreator;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag785.Tag52aCreator;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag785.Tag56aCreator;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag785.Tag57aCreator;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag785.Tag59aCreator;
import com.brilliance.isc.swift.objmtconvert.model.mt7xx.tag.tag785.Tag72ZCreator;
import com.brilliance.isc.swift.objmtconvert.result.MtResult;
import lombok.Data;
import lombok.EqualsAndHashCode;

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

/**
 * @author wuzhe
 * @date 2023/2/27
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class MT785Creator extends AbsMTCreator {

    @Status("M")
    @TagName("20")
    @FieldDescription("Undertaking Number")
    @TagRegex("16x")
    //20
    private String undertakingNumber;
    @Status("O")
    @TagName("21")
    @FieldDescription("Related Referencer")
    @TagRegex("16x")
    //21
    private String relatedReference;
    @Status("M")
    @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("31C")
    @FieldDescription("Date of Issue")
    @TagRegex("6!n")
    //31C
    private String dateofIssue;
    @Status("M")
    @TagName({"59","59A"})
    @FieldDescription("Beneficiary")
    @TagRegex({"[/34x]<crlf>4*35x","[/34x]<crlf>4!a2!a2!c[3!c]"})
    //59a
    private ActnoBicAdrTagXXX beneficiary;
    @Status("O")
    @TagName({"56A","56D"})
    @FieldDescription("Advising Bank")
    @TagRegex({"[/1!a][/34x]<crlf>4!a2!a2!c[3!c]","[/1!a][/34x]<crlf>4*35x"})
    //56a
    private ActnoBicAdrTagXXX advisingBank;
    @Status("O")
    @TagName({"57A","57D"})
    @FieldDescription("'Advise Through' Bank")
    @TagRegex({"[/1!a][/34x]<crlf>4!a2!a2!c[3!c]","[/1!a][/34x]<crlf>4*35x"})
    //57a
    private ActnoBicAdrTagXXX adviseThroughBank;
    @Status("O")
    @TagName("31E")
    @FieldDescription("Final Date of Expiry")
    @TagRegex("6!n")
    //31E
    private String finalDateofExpiry;
    @Status("O")
    @TagName("72Z")
    @FieldDescription("Sender to Receiver Information")
    @TagRegex("6*35z")
    //72Z
    private ActnoBicAdrTagXXX sendertoReceiverInformation;
    @Status("O")
    @TagName("23X")
    @FieldDescription("File Identification")
    @TagRegex("4!c/65x")
    //23X
    private String fileIdentification;

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

    public MT785Creator() {
        super("785");
    }

    /**
     * 需要编写组装报文逻辑，调用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 Tag52aCreator(this));
            tagCreateList.add(new Tag31CCreator(this));
            tagCreateList.add(new Tag59aCreator(this));
            tagCreateList.add(new Tag56aCreator(this));
            tagCreateList.add(new Tag57aCreator(this));
            tagCreateList.add(new Tag31ECreator(this));
            tagCreateList.add(new Tag72ZCreator(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;
    }

}

