package cn.estsh.i3plus.pojo.softswitch.bean;

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.BlockSoftSwitchEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

/**
 * @Description : 适配套件
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2019-08-13 9:21
 * @Modify:
 */
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "BS_SUIT_CASE")
@Api(value = "适配套件", description = "适配套件")
public class BsSuitCase extends BaseBean {

    private static final long serialVersionUID = -281224716754866835L;
    @Column(name = "SUIT_CASE_NAME")
    @ApiParam(value = "套件名称")
    private String suitCaseName;

    @Column(name = "CASE_TYPE_ID")
    @ApiParam(value = "套件类型id(枚举)")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.CASE_TYPE.class)
    private Integer caseTypeId;

    public int getCaseTypeIdVal(){
        if(caseTypeId == null) {
            return -1;
        }
        return caseTypeId.intValue();
    }

    public String getCaseTypeTxt() {
        return BlockSoftSwitchEnumUtil.CASE_TYPE.valueOfDescription(getCaseTypeIdVal());
    }

    @Column(name = "CASE_DETAIL_ID")
    @ApiParam(value = "适配器明细id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long caseDetailId;

    @Column(name = "SUIT_TYPE_ID")
    @ApiParam(value = "适配类型id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long suitTypeId;

    public long getSuitTypeIdVal(){
        if(suitTypeId == null){
            return -1;
        }
        return suitTypeId.longValue();
    }

    @Column(name = "SUIT_TYPE_NAME_RDD")
    @ApiParam(value = "适配类型名称")
    private String suitTypeNameRdd;

    @Column(name = "SUIT_CASE_CODE")
    @ApiParam(value = "适配器代码")
    private String suitCaseCode;

    @Column(name = "SUIT_MODE_ID")
    @ApiParam(value = "适配模式(枚举,主动，被动)")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.SUIT_MODE.class)
    private Integer suitModeId;

    @Column(name = "SUIT_ACTION_ID")
    @ApiParam(value = "Server 适配命令")
    private Integer suitActionId;

    @Column(name = "SUIT_CASE_HOST")
    @ApiParam(value = "适配主机")
    private String suitCaseHost;

    @Column(name = "SUIT_CASE_PORT")
    @ApiParam(value = "适配端口")
    private Integer suitCasePort;

    @Column(name = "SUIT_CASE_URL")
    @ApiParam(value = "适配URL")
    private String suitCaseURL;

    @Column(name = "IS_NEED_CERTIFICATION")
    @ApiParam(value = "是否需要认证")
    private Integer isNeedCertification;

    public int getIsNeedCertificationVal(){
        if(isNeedCertification==null){
            return CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
        }
        return isNeedCertification.intValue();
    }

    @Column(name = "IS_SAVE_EMPTY_MSG")
    @ApiParam(value = "是否保存空报文")
    @AnnoOutputColumn(refClass = CommonEnumUtil.TRUE_OR_FALSE.class)
    private Integer isSaveEmptyMsg;

    public int getIsSaveEmptyMsgVal(){
        return isSaveEmptyMsg == null ? CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue() : isSaveEmptyMsg;
    }

    @Column(name = "IS_PUSH_MQ")
    @ApiParam(value = "是否推送MQ")
    private Integer isPushMQ;

    @Column(name = "RESULT_SOFT_TYPE",columnDefinition = "int default 0")
    @ApiParam(value = "同步调用微服务")
    private Integer resultSoftType;
    public String getResultSoftTypeTxt() {
        return resultSoftType == null ? null : CommonEnumUtil.SOFT_TYPE.valueOfDescription(resultSoftType);
    }

    @Column(name = "SSL_KEY_ID")
    @ApiParam(value = "证书id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long sslKeyId;

    @Column(name = "SUIT_DATA_TYPE")
    @ApiParam(value = "适配报文类型")
    private Integer suitDataType;

    public Integer getSuitDataType(){
        if(suitDataType == null){
            suitDataType = BlockSoftSwitchEnumUtil.SUIT_DATA_TYPE.XML.getValue();
        }
        return suitDataType;
    }

    @Column(name = "REGULAR_SUIT_NUM")
    @ApiParam(value = "定时适配次数")
    private Integer regularSuitNum;

    public int getRegularSuitNumVal(){
        if(regularSuitNum == null){
            return -1;
        }
        return regularSuitNum.intValue();
    }

    public int addRegularSuitNum(){
        if(regularSuitNum == null){
            return 0;
        }
        return ++regularSuitNum;
    }

    @Column(name = "INITIATIVE_SUIT_NUM")
    @ApiParam(value = "主动适配测试")
    private Integer initiativeSuitNum;

    public int getInitiativeSuitNumVal(){
        if(initiativeSuitNum == null){
            return -1;
        }
        return initiativeSuitNum.intValue();
    }

    public int addInitiativeSuitNum(){
        if(initiativeSuitNum == null){
            initiativeSuitNum = 0;
        }
        return ++regularSuitNum;
    }

    @Column(name = "SUCCESS_NUM")
    @ApiParam(value = "成功次数")
    private Integer successNum;

    public int getSuccessNumVal(){
        if(successNum == null){
            successNum = -1;
        }
        return successNum.intValue();
    }

    public int addSuccessNum(){
        if(successNum == null){
            successNum = 0;
        }
        return ++successNum;
    }

    @Column(name = "FAIL_NUM")
    @ApiParam(value = "失败次数")
    private Integer failNum;

    public int getFailNumVal(){
        if(failNum == null){
            return -1;
        }
        return failNum;
    }

    public int addFailNum(){
        if(failNum == null){
            failNum =0;
        }
        return ++failNum;
    }

    @Column(name = "COUNT_NUM")
    @ApiParam(value = "总次数")
    private Integer countNum;

    public int getCountNumVal(){
        if(countNum == null){
            countNum = -1;
        }
        return countNum.intValue();
    }

    public int addCountNum(){
        if(countNum == null){
            countNum = 0;
        }
        return ++countNum;
    }

    @Column(name = "SUIT_CASE_DESCRIPTION")
    @ApiParam(value = "适配器描述")
    private String suitCaseDescription;

    @Column(name = "SUIT_CASE_STATUS")
    @ApiParam(value = "适配器状态")
    private Integer suitCaseStatus;

    @Column(name = "BIND_BUSI_SCRIPT_CODE")
    @ApiParam(value = "绑定业务脚本Code")
    private String bindBusiScriptCode;

    @Transient
    @ApiParam(value = "适配器套件明细")
    private  Object bsSuitCaseDetail;

    @Transient
    @ApiParam(value = "适配器套件明细")
    private  BsSslKey bsSslKey;

    @Transient
    @ApiParam(value = "适配器套件明细")
    private String paramXml;

    @Transient
    @ApiParam(value = "适配器参数")
    private List<BsSuitCaseParam> bsSuitCaseParamList;

    @Transient
    @ApiParam(value = "入参转换")
    private List<BsParamAdapter> bsInParamAdapterList;

    @Transient
    @ApiParam(value = "出参转换")
    private List<BsParamAdapter> bsOutParamAdapterList;
}


