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 com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.math.NumberUtils;
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
@XStreamAlias("param")
@EqualsAndHashCode(callSuper = true)
@Table(name = "BS_SUIT_CASE_PARAM")
@Api(value = "适配器出入参", description = "适配器出入参")
public class BsSuitCaseParam extends BaseBean {

    private static final long serialVersionUID = -2186546861255097857L;
    @Column(name = "SUIT_CASE_ID")
    @ApiParam(value = "套件id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long suitCaseId;

    @Column(name = "SUIT_CASE_CODE_RDD")
    @ApiParam(value = "套件代码")
    private String suitCaseCodeRdd;

    @Column(name = "PARAM_TYPE_ID")
    @ApiParam(value = "参数类型，枚举(出,入)")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.PARAM_TYPE.class)
    private Integer paramTypeId;

    @Column(name = "PARAM_NAME")
    @ApiParam(value = "参数名称)")
    private String paramName;

    @Column(name = "PARENT_PARAM_Id")
    @ApiParam(value = "上级参数id")
    private String parentParamId;

    @Column(name = "PARENT_PARAM_NAME")
    @ApiParam(value = "上级参数名称)")
    private String parentParamName;

    @Column(name = "PARAM_VAL_TYPE_ID")
    @ApiParam(value = "参数值类型")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.PARAM_VALUE_TYPE.class)
    private Integer paramValTypeId;

    @JsonIgnore
    public int getParamValTypeIdVal() {
        return paramValTypeId == null ? NumberUtils.INTEGER_MINUS_ONE : paramValTypeId.intValue();
    }

    @Column(name = "PARAM_SORT")
    @ApiParam(value = "参数参数排序")
    private Integer paramSort;

    @Column(name = "PARAM_DEFAULT_VALUE")
    @ApiParam(value = "参数默认值")
    private String paramDefaultValue;

    @Column(name = "PARAM_DESCRIPTION")
    @ApiParam(value = "参数描述")
    private String paramDescription;

    @Transient
    @ApiParam(value = "参数值")
    private Object paramValue;

    @JsonIgnore
    public String getParamValueStr() {
        if (paramValue == null) {
            return null;
        }
        return paramValue.toString();
    }

    @Transient
    @ApiParam(value = "子级参数")
    private List<BsSuitCaseParam> bsSuitCaseParamList;

}

