package cn.stylefeng.team.meta.api.entity;

import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.util.sort.GetSortKey;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;

@TableName("devops_meta_field")
@Data
@EqualsAndHashCode(callSuper = true)
public class MetaField extends BaseEntity implements GetSortKey {

    @TableId(value = "field_id", type = IdType.ASSIGN_ID)
    @ChineseDescription("字段id")
    private Long fieldId;

    @TableField("business_category_id")
    @ChineseDescription("所属业务分类id")
    private Long businessCategoryId;

    @TableField("business_id")
    @ChineseDescription("所属业务id")
    private Long businessId;

    @TableField("meta_model_id")
    @ChineseDescription("所属模型id")
    private Long metaModelId;

    @TableField("meta_definition_id")
    @ChineseDescription("所属模型定义id")
    private Long metaDefinitionId;

    @TableField("field_code")
    @ChineseDescription("属性编码(下划线命名)，例如：user_account")
    private String fieldCode;

    @TableField("field_type")
    @ChineseDescription(
            "字段类型：10-可变字符串，11-超长字符串，12-固定长度字符串，20-整型，21-长整型，30-浮点数，50-日期时间，51-日期，52-时间，60-对象，61-列表（集合）")
    private Integer fieldType;

    @TableField("field_length")
    @ChineseDescription("长度")
    private Integer fieldLength;

    @TableField("decimal_length")
    @ChineseDescription("小数位数")
    private Integer decimalLength;

    @TableField("not_empty_flag")
    @ChineseDescription("非空标识：Y-非空，N-可为空")
    private String notEmptyFlag;

    @TableField("key_flag")
    @ChineseDescription("主键标识：Y-主键，N-非主键")
    private String keyFlag;

    @TableField("default_value")
    @ChineseDescription("默认值")
    private String defaultValue;

    @TableField("real_flag")
    @ChineseDescription("是否是真实字段：Y-真实，N-不真实")
    private String realFlag;

    @TableField("description")
    @ChineseDescription("描述")
    private String description;

    @TableField("default_form_component")
    @ChineseDescription("默认元素绑定的表单元素类型")
    private String defaultFormComponent;

    @TableField("fld_sort")
    @ChineseDescription("排序")
    private BigDecimal fldSort;

    @TableField(value = "tenant_id", fill = FieldFill.INSERT)
    @ChineseDescription("租户id")
    private Long tenantId;

    @TableField(value = "version_flag", fill = FieldFill.INSERT)
    @ChineseDescription("乐观锁")
    @Version
    private Long versionFlag;

    @Override
    public Object getSortKey() {
        return this.getFieldId();
    }

}
