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

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.BlockFormEnumUtil;
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.ColumnDefault;
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 : alwaysfrin
 * @CreateDate : 2019-02-27 10:53
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name="bf_element_property")
@Api(value="对象元素属性",description = "对象元素属性 相当于数据对象属性的扩展")
public class BfElementProperty extends BaseBean {

    private static final long serialVersionUID = 8391877375302721425L;
    @Column(name = "ELEMENT_ID")
    @ApiParam(value = "对象元素ID", example = "-1")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long elementId;

    @Column(name = "OBJECT_ID")
    @ApiParam(value = "数据对象ID", example = "-1")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long objectId;

    @Column(name = "DATA_OBJECT_PROPERTY_ID")
    @ApiParam(value = "数据对象属性ID", example = "-1")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long dataObjectPropertyId;

    // 暂用来区分存储过程出入参数信息
    @AnnoOutputColumn(refClass = BlockFormEnumUtil.ORIGIN_PROPERTY_TYPE.class)
    @ColumnDefault("10")
    @Column(name="ORIGIN_PROPERTY_TYPE")
    @ApiParam(value ="原始列类型")
    private Integer originPropertyType;

    public String getOriginPropertyTypeTxt() {
        return originPropertyType == null ? BlockFormEnumUtil.ORIGIN_PROPERTY_TYPE.NORMAL_PROPERTY.getDescription()
                : BlockFormEnumUtil.ORIGIN_PROPERTY_TYPE.valueOfDescription(originPropertyType);
    }

    @Column(name="PROPERTY_TYPE")
    @ApiParam(value ="属性类型")
    private Integer propertyType;

    @Column(name="PROPERTY_TYPE_NAME_RDD")
    @ApiParam(value ="属性类型名称")
    private String propertyTypeNameRdd;

    @Column(name="PROPERTY_NAME")
    @ApiParam(value ="元素属性名称")
    private String propertyName;

    @Column(name="PROPERTY_CODE_RDD")
    @ApiParam(value ="类属性名称")
    private String propertyCodeRdd;

    @Column(name="PROPERTY_DEFAULT_VALUE")
    @ApiParam(value ="元素默认值")
    private String propertyDefaultValue;

    @Column(name = "PROPERTY_VALUE_NOT_NULL")
    @ApiParam(value = "是否必填")
    private Integer propertyValueNotNull;

    public boolean isPropValNotNull() {
        return propertyValueNotNull == null || propertyValueNotNull == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();
    }

    @Column(name = "PROPERTY_IS_FIND")
    @ApiParam(value = "是否查询条件")
    private Integer propertyIsFind;

    @Column(name = "PROPERTY_SHOW_STATUS")
    @ApiParam(value = "显示状态")
    private Integer propertyShowStatus;

    @Column(name = "PROPERTY_INPUT_TXT")
    @ApiParam(value = "输入提示")
    private String propertyInputTxt;

    @Column(name="PROPERTY_LABEL_TXT")
    @ApiParam(value ="元素提示")
    private String propertyLabelTxt;

    @Column(name = "PROPERTY_LENGTH")
    @ApiParam(value = "属性长度")
    private Integer propertyLength;

    @Column(name = "PROPERTY_ADD_STATUS")
    @ApiParam(value = "新增可见状态")
    private Integer propertyAddStatus;

    @Column(name = "PROPERTY_EDIT_STATUS")
    @ApiParam(value = "编辑可见状态")
    private Integer propertyEditStatus;

    @Column(name = "PROPERTY_IS_SORT")
    @ApiParam(value = "是否可排序")
    private Integer propertyIsSort;

    @Column(name = "PROPERTY_SORT")
    @ApiParam(value = "显示顺序")
    private Integer propertySort;

    @Column(name = "IS_SUPPORT_IMPORT")
    @ApiParam(value = "是否支持导入")
    private Integer isSupportImport;

    public boolean isSupportImport() {
        return isSupportImport != null && isSupportImport == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();
    }

    @Column(name = "PROPERTY_CONTROL_TYPE")
    @ApiParam(value = "控件类型")
    private Integer propertyControlType;

    @Column(name = "PROPERTY_CONTROL_FORMAT")
    @ApiParam(value = "控件显示格式")
    private String propertyControlFormat;

    @Column(name = "PROPERTY_CONTROL_REF_KEY")
    @ApiParam(value = "控件引用RefKey")
    private String propertyControlRefKey;

    @Column(name = "PROPERTY_CONTROL_TEXT_KEY")
    @ApiParam(value = "控件显示文本Key")
    private String propertyControlTextKey;

    @Column(name = "PROPERTY_CONTROL_VALUE_KEY")
    @ApiParam(value = "控件引用值Key")
    private String propertyControlValueKey;

    @Column(name = "PROPERTY_DESCRIPTION")
    @ApiParam(value = "属性描述")
    private String propertyDescription;

    @Column(name="PROPERTY_CSS_STYLE")
    @ApiParam(value ="元素样式")
    private String propertyCssStyle;

    @Transient
    @ApiParam(value ="元素值")
    private transient Object propertyFormValue;

    @Transient
    @ApiParam(value = "对象属性信息")
    @AnnoOutputColumn(hidden = true)
    private BfDataObjectProperty objectProperty;

    @Transient
    @ApiParam(value ="是否为唯一约束字段")
    private transient Integer isUniqueProperty;

    @Transient
    @ApiParam(value ="拾取关联属性")
    private List<BfElementPickUpProperty> pickUpPropertyList;

//    public Object getFormValue() {
//        return propertyFormValue == null ? propertyDefaultValue : propertyFormValue;
//    }
}
