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.commontag.ActnoBicAdrTagXXX;
import com.brilliance.isc.swift.objmtconvert.model.mt1xx.mt1XXAbsCreator.MT101AbsCreator;
import com.brilliance.isc.swift.objmtconvert.model.mt1xx.tag.tag101.*;
import com.brilliance.isc.swift.objmtconvert.result.MtResult;

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

/**
 * MT101报文的A部分.
 * @author liusheng
 */
public class MT101Creator extends AbsMTCreator {
    @Status("M")
    @TagName("20")
    @FieldDescription("Sender's Reference")
    @TagRegex("16x")
    //20
    private String sendersReference;

    @Status("O")
    @TagName("21R")
    @FieldDescription("Customer Specified Reference")
    @TagRegex("16x")
    //21R
    private String customerSpecifiedReference;

    @Status("M")
    @TagName("28D")
    @FieldDescription("Message Index/Total")
    @TagRegex("5n/5n")
    //28D
    private String messageIndexTotal;

    @Status("O")
    @TagName({"50C", "50L"})
    @FieldDescription("Instructing Party")
    @TagRegex({"4!a2!a2!c[3!c]", "35x"})
    //50a
    private ActnoBicAdrTagXXX instructingParty;

    @Status("O")
    @TagName({"50F", "50G", "50H"})
    @FieldDescription("Ordering Customer")
    @TagRegex({"35x\r\n4*(1!n/33x)", "/34x\r\n4!a2!a2!c[3!c]", "/34x\r\n4*35x"})
    //50a
    private ActnoBicAdrTagXXX orderingCustomer;

    @Status("O")
    @TagName({"52A", "52C"})
    @FieldDescription("Account Servicing Institution")
    @TagRegex({"[/1!a][/34x]\r\n4!a2!a2!c[3!c]", "/34x"})
    //52a
    private ActnoBicAdrTagXXX accountServicingInstitution;

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

    @Status("M")
    @TagName("30")
    @FieldDescription("Requested Execution Date")
    @TagRegex("6!n")
    //30
    private String requestedExecutionDate;

    @Status("O")
    @TagName("25")
    @FieldDescription("Authorisation")
    @TagRegex("35x")
    //25
    private String authorisation;

    //循环域
    private List<MT101AbsCreator> cycleDomain;

    public MT101Creator() { super(); }

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

    public String getSendersReference() {
        return sendersReference;
    }

    public void setSendersReference(String sendersReference) {
        this.sendersReference = sendersReference;
    }

    public String getCustomerSpecifiedReference() {
        return customerSpecifiedReference;
    }

    public void setCustomerSpecifiedReference(String customerSpecifiedReference) {
        this.customerSpecifiedReference = customerSpecifiedReference;
    }

    public String getMessageIndexTotal() {
        return messageIndexTotal;
    }

    public void setMessageIndexTotal(String messageIndexTotal) {
        this.messageIndexTotal = messageIndexTotal;
    }

    public ActnoBicAdrTagXXX getInstructingParty() {
        return instructingParty;
    }

    public void setInstructingParty(ActnoBicAdrTagXXX instructingParty) {
        this.instructingParty = instructingParty;
    }

    public ActnoBicAdrTagXXX getOrderingCustomer() {
        return orderingCustomer;
    }

    public void setOrderingCustomer(ActnoBicAdrTagXXX orderingCustomer) {
        this.orderingCustomer = orderingCustomer;
    }

    public ActnoBicAdrTagXXX getAccountServicingInstitution() {
        return accountServicingInstitution;
    }

    public void setAccountServicingInstitution(ActnoBicAdrTagXXX accountServicingInstitution) {
        this.accountServicingInstitution = accountServicingInstitution;
    }

    public ActnoBicAdrTagXXX getSendingInstitution() {
        return sendingInstitution;
    }

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

    public String getRequestedExecutionDate() {
        return requestedExecutionDate;
    }

    public void setRequestedExecutionDate(String requestedExecutionDate) {
        this.requestedExecutionDate = requestedExecutionDate;
    }

    public String getAuthorisation() {
        return authorisation;
    }

    public void setAuthorisation(String authorisation) {
        this.authorisation = authorisation;
    }

    public List<MT101AbsCreator> getCycleDomain() {
        return cycleDomain;
    }

    public void setCycleDomain(List<MT101AbsCreator> cycleDomain) {
        this.cycleDomain = cycleDomain;
    }

    @Override
    public void pack() {
        //MtResult mtResult = new MtResult();
        List<AbsTagCreate> tagCreateList = new ArrayList<>();
        try{
            tagCreateList.add(new Tag20Creator(this));
            tagCreateList.add(new Tag21RCreator(this));
            tagCreateList.add(new Tag28DCreator(this));
            tagCreateList.add(new Tag50aCreator(this));
            tagCreateList.add(new Tag50a2Creator(this));
            tagCreateList.add(new Tag52aCreator(this));
            tagCreateList.add(new Tag51ACreator(this));
            tagCreateList.add(new Tag30Creator(this));
            tagCreateList.add(new Tag25Creator(this));
            tagCreateList.add(new TagCycleCreator(this));

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