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

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

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

/**
 * MT101报文的B部分，用于提供交易详情，可循环.
 * @author liusheng
 */
public class MT101AbsCreator extends AbsMTCreator {

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

    @Status("O")
    @TagName("21F")
    @FieldDescription("F/X Deal Reference")
    @TagRegex("16x")
    //21F
    private String FXDealReference;

    @Status("O")
    @TagName("23E")
    @FieldDescription("Instruction Code")
    @TagRegex("4!c[/30x]")
    //23E
    private LinkedList<String> instructionCode;

    @Status("M")
    @TagName("32B")
    @FieldDescription("Currency/Transaction Amount")
    @TagRegex("3!a15d")
    //32B
    private String currencyTransactionAmount;

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

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

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

    @Status("O")
    @TagName({"56A", "56C", "56D"})
    @FieldDescription("Intermediary")
    @TagRegex({"[/1!a][/34x]<crlf>4!a2!a2!c[3!c]", "/34x", "[/1!a][/34x]<crlf>4*35x"})
    //56a
    private ActnoBicAdrTagXXX intermediary;

    @Status("O")
    @TagName({"57A", "57C", "57D"})
    @FieldDescription("Account With Institution")
    @TagRegex({"[/1!a][/34x]<CRLF>4!a2!a2!c[3!c]", "/34x", "[/1!a][/34x]4*35x"})
    //57a
    private ActnoBicAdrTagXXX accountWithInstitution;

    @Status("M")
    @TagName({"59", "59A", "59F"})
    @FieldDescription("Beneficiary")
    @TagRegex({"[/34x]<crlf>4*35x", "[/34x]<crlf>4!a2!a2!c[3!c]", "[/34x]<crlf>4*(1!n/33x)"})
    //59a
    private ActnoBicAdrTagXXX beneficiary;

    @Status("O")
    @TagName("70")
    @FieldDescription("Remittance Information")
    @TagRegex("4*35x")
    //70
    private String remittanceInformation;

    @Status("O")
    @TagName("77B")
    @FieldDescription("Regulatory Reporting")
    @TagRegex("3*35x")
    //77B
    private String regulatoryReporting;

    @Status("O")
    @TagName("33B")
    @FieldDescription("Currency/Original Ordered Amount")
    @TagRegex("3!a15d")
    //33B
    private String currencyOriginalOrderedAmount;

    @Status("M")
    @TagName("71A")
    @FieldDescription("Details of Charges")
    @TagRegex("3!a")
    //71A
    private String detailsOfCharges;

    @Status("O")
    @TagName("25A")
    @FieldDescription("ChargesAccount")
    @TagRegex("/34x")
    //25A
    private String chargesAccount;

    @Status("O")
    @TagName("36")
    @FieldDescription("Exchange Rate")
    @TagRegex("12d")
    //36
    private String exchangeRate;

    public MT101AbsCreator() { super(); }

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

    public String getTransactionReference() {
        return transactionReference;
    }

    public void setTransactionReference(String transactionReference) {
        this.transactionReference = transactionReference;
    }

    public String getFXDealReference() {
        return FXDealReference;
    }

    public void setFXDealReference(String FXDealReference) {
        this.FXDealReference = FXDealReference;
    }

    public LinkedList<String> getInstructionCode() {
        return instructionCode;
    }

    public void setInstructionCode(LinkedList<String> instructionCode) {
        this.instructionCode = instructionCode;
    }

    public String getCurrencyTransactionAmount() {
        return currencyTransactionAmount;
    }

    public void setCurrencyTransactionAmount(String currencyTransactionAmount) {
        this.currencyTransactionAmount = currencyTransactionAmount;
    }

    public ActnoBicAdrTagXXX getInstructionParty() {
        return instructionParty;
    }

    public void setInstructionParty(ActnoBicAdrTagXXX instructionParty) {
        this.instructionParty = instructionParty;
    }

    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 getIntermediary() {
        return intermediary;
    }

    public void setIntermediary(ActnoBicAdrTagXXX intermediary) {
        this.intermediary = intermediary;
    }

    public ActnoBicAdrTagXXX getAccountWithInstitution() {
        return accountWithInstitution;
    }

    public void setAccountWithInstitution(ActnoBicAdrTagXXX accountWithInstitution) {
        this.accountWithInstitution = accountWithInstitution;
    }

    public ActnoBicAdrTagXXX getBeneficiary() {
        return beneficiary;
    }

    public void setBeneficiary(ActnoBicAdrTagXXX beneficiary) {
        this.beneficiary = beneficiary;
    }

    public String getRemittanceInformation() {
        return remittanceInformation;
    }

    public void setRemittanceInformation(String remittanceInformation) {
        this.remittanceInformation = remittanceInformation;
    }

    public String getRegulatoryReporting() {
        return regulatoryReporting;
    }

    public void setRegulatoryReporting(String regulatoryReporting) {
        this.regulatoryReporting = regulatoryReporting;
    }

    public String getCurrencyOriginalOrderedAmount() {
        return currencyOriginalOrderedAmount;
    }

    public void setCurrencyOriginalOrderedAmount(String currencyOriginalOrderedAmount) {
        this.currencyOriginalOrderedAmount = currencyOriginalOrderedAmount;
    }

    public String getDetailsOfCharges() {
        return detailsOfCharges;
    }

    public void setDetailsOfCharges(String detailsOfCharges) {
        this.detailsOfCharges = detailsOfCharges;
    }

    public String getChargesAccount() {
        return chargesAccount;
    }

    public void setChargesAccount(String chargesAccount) {
        this.chargesAccount = chargesAccount;
    }

    public String getExchangeRate() {
        return exchangeRate;
    }

    public void setExchangeRate(String exchangeRate) {
        this.exchangeRate = exchangeRate;
    }
    public void pack() {
       // MtResult mtResult = new MtResult();
        List<AbsTagCreate> tagCreateList = new ArrayList<>();
        try{
            tagCreateList.add(new Tag21Creator(this));
            tagCreateList.add(new Tag21FCreator(this));
            tagCreateList.add(new Tag23ECreator(this));
            tagCreateList.add(new Tag32BCreator(this));
            tagCreateList.add(new Tag50aCreator(this));
            tagCreateList.add(new Tag50a2Creator(this));
            tagCreateList.add(new Tag52aCreator(this));
            tagCreateList.add(new Tag56aCreator(this));
            tagCreateList.add(new Tag57aCreator(this));
            tagCreateList.add(new Tag59aCreator(this));
            tagCreateList.add(new Tag70Creator(this));
            tagCreateList.add(new Tag77BCreator(this));
            tagCreateList.add(new Tag33BCreator(this));
            tagCreateList.add(new Tag71ACreator(this));
            tagCreateList.add(new Tag25ACreator(this));
            tagCreateList.add(new Tag36Creator(this));

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