package com.brilliance.isc.common.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import com.brilliance.isc.annotation.OitByObjectInr;
import com.brilliance.isc.bo.*;
//import com.brilliance.isc.common.component.PtsptaToolComponent;
//import com.brilliance.isc.common.context.SpringEnvContext;
import com.brilliance.isc.utils.SpringUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.beanutils.MethodUtils;

import static com.brilliance.mda.runtime.mda.Constants.NULLSTR;
@OitByObjectInr(objtype = "pty",objinrnam = "ptyinr")
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@ApiModel(value = "交易角色参与方", description = "交易角色参与方")
public class PtsptaVo extends AbstractCommonVo {

    private static Logger logger = LoggerFactory.getLogger(PtsptaVo.class);

    @ApiModelProperty(value = "参与方inr", name = "ptsinr", required = false)
    private String ptsinr = NULLSTR;

    @ApiModelProperty(value = "参与方角色", name = "rol", required = true)
    private String rol = NULLSTR;

    @ApiModelProperty(value = "参与方名称", name = "name", required = true)
    private String nam = NULLSTR;

    @ApiModelProperty(value = "参与者扩展名称", name = "ptanam1")
    private String ptanam1 = NULLSTR;

    @ApiModelProperty(value = "参与方PTY信息的INR", name = "ptyinr", required = true)
    private String ptyinr = NULLSTR;

    @ApiModelProperty(value = "参与方PTA信息的INR", name = "ptainr", required = true)
    private String ptainr = NULLSTR;

    @ApiModelProperty(value = "参与方编号", name = "extkey", required = true)
    private String extkey = NULLSTR;

    @ApiModelProperty(value = "默认DSP", name = "dftdsp", required = true)
    private String dftdsp = NULLSTR;

    @ApiModelProperty(value = "默认币种", name = "dftcur", required = true)
    private String dftcur = NULLSTR;

    @ApiModelProperty(value = "默认账号", name = "dftact", required = true)
    private String dftact = NULLSTR;

    @ApiModelProperty(value = "默认费用币种", name = "dftfeecur", required = true)
    private String dftfeecur = NULLSTR;

    @ApiModelProperty(value = "默认账号所属参与者PTA信息的INR", name = "dftactptainr", required = true)
    private String dftactptainr = NULLSTR;

    @ApiModelProperty(value = "Default role for Settlement / settle via", name = "dftselrol", required = true)
    private String dftselrol = NULLSTR;

    @ApiModelProperty(value = "Grouping Rule of Amounts", name = "glggrpflg", required = true)
    private String glggrpflg = NULLSTR;

    @ApiModelProperty(value = "to be defaulted by user, if not I is used", name = "pansta", required = true)
    private String pansta = NULLSTR;

    @ApiModelProperty(value = "参与者类型", name = "ptytyp", required = true)
    private String ptytyp = NULLSTR;

    @ApiModelProperty(value = "参与者编号", name = "ptyextkey", required = true)
    private String ptyextkey = NULLSTR;

    @ApiModelProperty(value = "参与者名称地址", name = "adrblk", required = true)
    private String adrblk = NULLSTR;

    @ApiModelProperty(value = "Flag whether role is set", name = "rolsetflg", required = true)
    private String rolsetflg = NULLSTR;
    /**
     * 是否是临时pts
     */
    private String tmpflg;

    /**
     * Pts类型：B 银行
     */
    private String typflg;
	private String mdtflg = NULLSTR;

//    private transient FieldHolder<String> tmpflg = new FieldConstantHolder<>();

    private String chnguaflg = NULLSTR;

    private String namelc = NULLSTR;

    private String adrelc = NULLSTR;

    private String cnnam = NULLSTR;

    private String cnadr = NULLSTR;

    private String ennam = NULLSTR;

    private String enadr = NULLSTR;

    //申请人参考号
    private String ref = NULLSTR;

    //chinese address
    private String dbfadrblkcn = NULLSTR;

    //Risk Country from PTY
    private String rskcty = NULLSTR;

    private  String dbfadrblk = NULLSTR;

    /**
     * 是否创建临时地址选择条件
     */
    private boolean flg;

    /**
     * 语言格式(英文EN,中文ZH)
     */
    private String language;

    //Flag set, if PTS is in selection
    private  String selflg = NULLSTR;

    private Pts pts;

    @JsonIgnore
    private Pta pta;

    @JsonIgnore
    private Adr adr;

    @JsonIgnore
    private Bch bch;

    @JsonIgnore
    private Bnk bnk;

    @JsonIgnore
    private Bnl bnl;

    @JsonIgnore
    @JSONField(serialize = false)
    public String getRolsetflg() {
        try {
           boolean ptsIsRolSet = (Boolean)MethodUtils.invokeMethod(SpringUtils.getBean("PtsptaToolComponent"), "ptsIsRolSet", this);
           if(ptsIsRolSet){
               return "Y";
           }
        }catch (Exception e){
            logger.error("判断Rolsetflg发生异常:{}",e);
        }
        return "";
    }

    public String getPtsinr() {
        if (pts != null && !MdaUtils.isEmpty(pts.getInr())){
            return pts.getInr();
        }
        return ptsinr;
    }

    public void reset() {
        if (pts == null) {
            pts = new Pts();
        }
        if (pta == null) {
            pta = new Pta();
        }
        if (adr == null) {
            adr = new Adr();
        }
        if (bch == null) {
            bch = new Bch();
        }
        if (bnk == null) {
            bnk = new Bnk();
        }
        if (bnl == null) {
            bnl = new Bnl();
        }
    }

    public String getRol() {
        if (pts != null && !MdaUtils.isEmpty(pts.getRol())){
            return pts.getRol();
        }
        return rol;
    }

    public String getNam() {
        if (pts != null && !MdaUtils.isEmpty(pts.getNam())){
            return pts.getNam();
        }
        return nam;
    }

    public String getPtanam1() {
        if (pta != null && !MdaUtils.isEmpty(pta.getNam1())){
            return pta.getNam1();
        }
        return ptanam1;
    }

    public String getPtyinr() {
        if (pts != null && !MdaUtils.isEmpty(pts.getPtyinr())){
            return pts.getPtyinr();
        }
        return ptyinr;
    }

    public String getPtainr() {
        if (pts != null && !MdaUtils.isEmpty(pts.getPtainr())){
            return pts.getPtainr();
        }
        return ptainr;
    }

    public String getExtkey() {
        if (pts != null && !MdaUtils.isEmpty(pts.getExtkey())){
            return pts.getExtkey();
        }
        return extkey;
    }

    public String getDftdsp() {
        if (pts != null && !MdaUtils.isEmpty(pts.getDftdsp())){
            return pts.getDftdsp();
        }
        return dftdsp;
    }

    public String getDftcur() {
        if (pts != null && !MdaUtils.isEmpty(pts.getDftcur())){
            return pts.getDftcur();
        }
        return dftcur;
    }

    public String getDftact() {
        if (pts != null && !MdaUtils.isEmpty(pts.getDftact())){
            return pts.getDftact();
        }
        return dftact;
    }

    public String getDftfeecur() {
        if (pts != null && !MdaUtils.isEmpty(pts.getDftfeecur())){
            return pts.getDftfeecur();
        }
        return dftfeecur;
    }

    public String getDftactptainr() {
        if (pts != null && !MdaUtils.isEmpty(pts.getDftactptainr())){
            return pts.getDftactptainr();
        }
        return dftactptainr;
    }

    public String getDftselrol() {
        if (pts != null && !MdaUtils.isEmpty(pts.getDftsetrol())){
            return pts.getDftsetrol();
        }
        return dftselrol;
    }

    public String getGlggrpflg() {
        if (pts != null && !MdaUtils.isEmpty(pts.getGlggrpflg())){
            return pts.getGlggrpflg();
        }
        return glggrpflg;
    }

    public String getAdrblk() {
        if (pts != null && !MdaUtils.isEmpty(pts.getAdrblk())){
            return pts.getAdrblk();
        }
        return adrblk;
    }

    public String getRef() {
        if (pts != null && !MdaUtils.isEmpty(pts.getRef())){
            return pts.getRef();
        }
        return ref;
    }

    /**
     * 获取英文的名称地址
     * @return
     */
    public String getNameAndAddress() {
        if (pts != null) {
            return pts.getAdrblk();
        }
        return "";
    }
}
