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.mt4xx.tag.tag496.*;

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

/**
 * MT496报文，格式与n96通用报文格式相同。
 * MT and Date of the Original Message暂时按照11S处理。
 * Copy of fields暂时搁置。
 * @author liusheng
 */
public class MT496Creator extends AbsMTCreator {
    @Status("M")
    @TagName("20")
    @FieldDescription("Transaction Reference Number")
    @TagRegex("16x")
    //20
    private String transactionReferenceNumber;

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

    @Status("M")
    @TagName("76")
    @FieldDescription("Answers")
    @TagRegex("6*35x")
    //76
    private String answers;

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

    @Status("O")
    @TagName("11S")
    @FieldDescription("MT and Date of the Original Message")
    @TagRegex("3!n\r\n6!n\r\n[4!n6!n]")
    //11a
    //有11R和11S两个选项。先按11S处理。后续会需要修改tag196.Tag11aCreator类。
    private String mtDateTag11a;

    //11a  R/S
    @Status("O")
    @TagName("11R")
    @FieldDescription("MT and Date of the Original Message")
    @TagRegex("3!n<crlf>6!n<crlf>[4!n6!n]")
    private String mtAndDateoftheOriginalMessage;

    @Status("O")
    @TagName("79")
    @FieldDescription("Narrative Description of the Original Message to Which the Answer Relates")
    @TagRegex("35*50x")
    //79
    private String narrativeDescriptionOriginal;

    //来自其他报文的标签的拷贝，此栏位先不做处理。
/*    @FieldDescription("Copy of at least the Mandatory Fields of the Original Message")
    private List<AbsTagCreate> copyOfFields;*/

    public MT496Creator() { super("496"); }

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

    public String getTransactionReferenceNumber() {
        return transactionReferenceNumber;
    }

    public void setTransactionReferenceNumber(String transactionReferenceNumber) {
        this.transactionReferenceNumber = transactionReferenceNumber;
    }

    public String getRelatedReference() {
        return relatedReference;
    }

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

    public String getAnswers() {
        return answers;
    }

    public void setAnswers(String answers) {
        this.answers = answers;
    }

    public String getNarrative() {
        return narrative;
    }

    public void setNarrative(String narrative) {
        this.narrative = narrative;
    }

    public String getMtAndDateoftheOriginalMessage() {
        return mtAndDateoftheOriginalMessage;
    }

    public void setMtAndDateoftheOriginalMessage(String mtAndDateoftheOriginalMessage) {
        this.mtAndDateoftheOriginalMessage = mtAndDateoftheOriginalMessage;
    }

    public String getMtDateTag11a() {
        return mtDateTag11a;
    }

    public void setMtDateTag11a(String mtDateTag11a) {
        this.mtDateTag11a = mtDateTag11a;
    }

    public String getNarrativeDescriptionOriginal() {
        return narrativeDescriptionOriginal;
    }

    public void setNarrativeDescriptionOriginal(String narrativeDescriptionOriginal) {
        this.narrativeDescriptionOriginal = narrativeDescriptionOriginal;
    }

/*    public List<AbsTagCreate> getCopyOfFields() {
        return copyOfFields;
    }

    public void setCopyOfFields(List<AbsTagCreate> copyOfFields) {
        this.copyOfFields = copyOfFields;
    }*/

    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 Tag76Creator(this));
            tagCreateList.add(new Tag77ACreator(this));
            tagCreateList.add(new Tag11rCreator(this));
            tagCreateList.add(new Tag11sCreator(this));
            tagCreateList.add(new Tag79Creator(this));

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

