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

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.mt1xx.tag.tag195.*;

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

/**
 * MT195报文，格式与n95通用报文格式相同。
 * MT and Date of the Original Message暂时按照11S处理。
 * Copy of fields暂时搁置。
 * @author liusheng
 */
public class MT195Creator 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("75")
    @FieldDescription("Queries")
    @TagRegex("6*35x")
    //75
    private String queries;

    @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]")
    //11s
    //有11R和11S两个选项。先按11S处理。后续会需要修改tag195.Tag11aCreator类。
    private String mtDateTag11a;

    //11r  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 Message to Which the Query Relates")
    @TagRegex("35*50x")
    //79
    private String narrativeDescription;

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

    public MT195Creator() { super("195"); }

    public MT195Creator(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 getQueries() {
        return queries;
    }

    public void setQueries(String queries) {
        this.queries = queries;
    }

    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 getNarrativeDescription() {
        return narrativeDescription;
    }

    public void setNarrativeDescription(String narrativeDescription) {
        this.narrativeDescription = narrativeDescription;
    }

/*    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 Tag75Creator(this));
            tagCreateList.add(new Tag77ACreator(this));
            tagCreateList.add(new Tag11sCreator(this));
            tagCreateList.add(new Tag11rCreator(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;
    }
}
