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

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.BlockFormEnumUtil;
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 : Adair Peng
 * @CreateDate : 2019-03-21 13:14
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "BF_ELEMENT")
@Api(value = "对象元素基础", description = "元素基础表")
public class BfElement extends BaseBean {

    private static final long serialVersionUID = -3309080566388373068L;
    //外键关联数据对象主键
    @Column(name = "ELEMENT_INFO_ID")
    @ApiParam(value = "对象元素明细ID", example = "-1")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long elementInfoId;

    //外键关联数据对象主键
    @Column(name = "DATA_OBJECT_ID")
    @ApiParam(value = "数据对象ID", example = "-1")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long dataObjectId;

    //外键关联数据对象主键
    @Column(name = "ELEMENT_PROPERTY_PRIMARY_KEY")
    @ApiParam(value = "元素主键Key ", example = "-1")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long elementPropertyPrimaryKey;

    @Column(name="ELEMENT_PROPERTY_PRIMARY_KEY_NAME_RDD")
    @ApiParam(value ="元素主键Key名称")
    private String elementPropertyPrimaryKeyNameRdd;

    @Column(name="ELEMENT_TYPE")
    @ApiParam(value ="元素类型")
    private Integer elementType;

    @Column(name="ELEMENT_NAME")
    @ApiParam(value ="元素名称")
    private String elementName;

    @Column(name="ELEMENT_CODE")
    @ApiParam(value ="元素编码")
    private String elementCode;

    @Column(name = "IS_OBJECT_ADD")
    @ApiParam(value = "是否新增")
    private Integer isObjectAdd;

    public boolean isObjectAdd(){
        return isObjectAdd != null && isObjectAdd == BlockFormEnumUtil.ELEMENT_ADD_STATUS.ON.getValue();
    }

    @Column(name = "IS_OBJECT_EDIT")
    @ApiParam(value = "是否编辑")
    private Integer isObjectEdit;

    public boolean isObjectEdit(){
        return isObjectEdit != null && isObjectEdit == BlockFormEnumUtil.ELEMENT_EDIT_STATUS.ON.getValue();
    }

    @Column(name = "IS_OBJECT_DEL")
    @ApiParam(value = "是否删除")
    private Integer isObjectDel;

    public boolean isObjectDel(){
        return isObjectDel != null && isObjectDel == BlockFormEnumUtil.ELEMENT_DEL_STATUS.ON.getValue();
    }

    @Column(name = "IS_OBJECT_DEL_WEAK")
    @ApiParam(value = "是否弱删除")
    private Integer isObjectDelWeak;

    public boolean isObjectDelWeak(){
        return isObjectDelWeak != null && isObjectDelWeak == BlockFormEnumUtil.ELEMENT_DELETE_WEAK_STATUS.ON.getValue();
    }

    public Integer getIsObjectDelWeakVal(){
        return isObjectDelWeak == null ? BlockFormEnumUtil.ELEMENT_DELETE_WEAK_STATUS.OFF.getValue() : isObjectDelWeak.intValue();
    }

    @Column(name = "ELEMENT_DEL_WEAK_ATTR_ID")
    @ApiParam(value = "元素弱删除属性id")
    private Long elementDelWeakAttrId;

    @Column(name = "IS_OBJECT_VALID")
    @ApiParam(value = "是否有效")
    private Integer isObjectValid;

    public Integer getIsObjectValidVal(){
        return isObjectValid == null ? BlockFormEnumUtil.ELEMENT_VALID_STATUS.OFF.getValue() : isObjectValid.intValue();
    }

    public boolean isObjectValid(){
        return isObjectValid != null && isObjectValid == BlockFormEnumUtil.ELEMENT_VALID_STATUS.ON.getValue();
    }

    @Column(name = "ELEMENT_VALID_ATTR_ID")
    @ApiParam(value = "元素有效属性id")
    private Long elementValidAttrId;

    @Column(name = "IS_ORGANIZE_ISOLATION")
    @ApiParam(value = "是否组织隔离")
    private Integer isOrganizeIsolation;

    public Integer getIsOrganizeIsolationVal(){
        return isOrganizeIsolation == null ? BlockFormEnumUtil.ELEMENT_ORGANIZE_ISOLATION_STATUS.OFF.getValue() : isOrganizeIsolation.intValue();
    }

    public boolean isOrganizeIsolation(){
        return isOrganizeIsolation != null && isOrganizeIsolation == BlockFormEnumUtil.ELEMENT_ORGANIZE_ISOLATION_STATUS.ON.getValue();
    }

    @Column(name = "IS_OBJECT_EXPORT")
    @ApiParam(value = "是否导出")
    private Integer isObjectExport;

    @ColumnDefault("2")
    @Column(name = "IS_OBJECT_IMPORT")
    @ApiParam(value = "是否导入")
    private Integer isObjectImport;

    @Column(name="ELEMENT_SORT_ATTR_ID")
    @ApiParam(value ="默认排序属性")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long elementSortAttrId;

    @Column(name="ELEMENT_SORT_ATTR_CODE_RDD")
    @ApiParam(value ="默认排序属性名称")
    private String elementSortAttrCodeRdd;

    @Column(name="ELEMENT_SORT_ATTR_TYPE")
    @ApiParam(value ="默认排序规则")
    private Integer elementSortAttrType;

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

    @Column(name="ELEMENT_DESCRIPTION")
    @ApiParam(value ="元素描述")
    private String elementDescription;

    @Transient
    @ApiParam(value = "数据对象")
    private BfDataObject dataObject;

    @Transient
    @ApiParam(value = "数据对象")
    private BfElementProperty elementSortProperty;

    @Transient
    @ApiParam(value = "元素表单")
    private BfElementGrid elementGrid;

    @Transient
    @ApiParam(value = "元素树")
    private BfElementTree elementTree;

    @Transient
    @ApiParam(value = "元素属性信息")
    private List<BfElementProperty> propertyList;

    @Transient
    @ApiParam(value = "元素虚拟属性信息")
    private List<BfElementPropertyVirtual> propertyVirtualList;

    @Transient
    @ApiParam(value = "元素约束信息")
    private List<BfElementConstraint> constraintList;
}
