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


import com.brilliance.isc.swift.objmtconvert.model.commontag.ActnoBicAdrTagXXX;
import com.brilliance.isc.swift.objmtconvert.model.commontag.DcDateCurAmtTagXXX;
import com.brilliance.isc.swift.objmtconvert.model.commontag.TagResult;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.MethodUtils;


/**
 * @author gechengyang
 * @date 2023/2/18
 */
public abstract class AbsTagCreate {

    private  AbsMTCreator absMTCreator;

    public  AbsTagCreate(AbsMTCreator absMTCreator)
    {
        this.absMTCreator=absMTCreator;
    }

    public  abstract  void   creator();


    /**
     *
     * @param absMTCreator
     * @param name name为MTXXX对象 5X对象属性名
     */
    public  void handlerBicAdrCreator(AbsMTCreator absMTCreator, String name)
    {
        //actnoBicAdr51a
        ActnoBicAdrTagXXX actnoBicAdrTagXXX= null;
        try {
            actnoBicAdrTagXXX = (ActnoBicAdrTagXXX) MethodUtils.invokeMethod(absMTCreator,"get"+name.substring(0,1).toUpperCase()+name.substring(1));
        } catch (Exception e) {
          //  absMTCreator.getMtResult().setSuccess(false);
         //   absMTCreator.getMtResult().addDescription(e.getLocalizedMessage());
            throw new RuntimeException(e);
        }
        if(actnoBicAdrTagXXX!=null) {
            TagResult tagResult = actnoBicAdrTagXXX.getTagResult();
            if (tagResult != null && StringUtils.isNotEmpty(tagResult.getTagBefore())) {
                absMTCreator.set(tagResult.getTagBefore() + tagResult.getTagEnd(), tagResult.getValue());
            }
        }
    }
    /**
     *
     * @param absMTCreator
     * @param name name为MTXXX对象 3X对象属性名
     */
    public  void handlerCurAmtCreator(AbsMTCreator absMTCreator, String name)
    {
        //dcDateCurAmt32a
        DcDateCurAmtTagXXX dcDateCurAmtTagXXX = null;
        try {
            dcDateCurAmtTagXXX = (DcDateCurAmtTagXXX) MethodUtils.invokeMethod(absMTCreator,"get"+name.substring(0,1).toUpperCase()+name.substring(1));
        } catch (Exception e) {
           // absMTCreator.getMtResult().setSuccess(false);
          //  absMTCreator.getMtResult().addDescription(e.getLocalizedMessage());
            throw new RuntimeException(e);
        }
        if(dcDateCurAmtTagXXX !=null) {
            TagResult tagResult = dcDateCurAmtTagXXX.getTagResult();
            if (tagResult != null && StringUtils.isNotEmpty(tagResult.getTagBefore()) && tagResult.getTagEnd() != null) {
                absMTCreator.set(tagResult.getTagBefore() + tagResult.getTagEnd(), tagResult.getValue());
            }
        }
    }
}
