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

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.enumutil.BlockFormEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import io.swagger.annotations.ApiParam;
import lombok.Data;

import java.io.Serializable;

/**
 * @Description :
 * @Reference :
 * @Author : Adair Peng
 * @CreateDate : 2019-03-22 17:17
 * @Modify:
 **/
@Data
public class SqlColumnModel implements Serializable {
    private static final long serialVersionUID = -8437573966195980847L;
    //    isAutoIncrement	true	 	 	 	 isNullable	0	 isSigned	true	 getColumnDisplaySize	11	 getColumnLabel	id	 				getColumnName	id	 				getSchemaName		 getPrecision	11	 getScale	0	 getTableName	interceptor	 	 getColumnType	4	 getColumnTypeName	INT	 			 	 	 getColumnClassName	java.lang.Integer
//    isAutoIncrement	false	 	 	 	 isNullable	1	 isSigned	false	 getColumnDisplaySize	50	 getColumnLabel	name	 			getColumnName	name	 			getSchemaName		 getPrecision	50	 getScale	0	 getTableName	interceptor	 	 getColumnType	12	 getColumnTypeName	VARCHAR	 		 	 	 getColumnClassName	java.lang.String
//    isAutoIncrement	false	 	 	 	 isNullable	1	 isSigned	true	 getColumnDisplaySize	11	 getColumnLabel	age	 				getColumnName	age	 				getSchemaName		 getPrecision	11	 getScale	0	 getTableName	interceptor	 	 getColumnType	4	 getColumnTypeName	INT	 			 	 	 getColumnClassName	java.lang.Integer
//    isAutoIncrement	false	 	 	 	 isNullable	1	 isSigned	false	 getColumnDisplaySize	19	 getColumnLabel	date_time	 		getColumnName	date_time	 		getSchemaName		 getPrecision	19	 getScale	0	 getTableName	interceptor	 	 getColumnType	93	 getColumnTypeName	TIMESTAMP		 	 	 getColumnClassName	java.sql.Timestamp
//    isAutoIncrement	false	 	 	 	 isNullable	0	 isSigned	true	 getColumnDisplaySize	11	 getColumnLabel	test_num_not_null	getColumnName	test_num_not_null	getSchemaName		 getPrecision	11	 getScale	0	 getTableName	interceptor	 	 getColumnType	4	 getColumnTypeName	INT	 			 	 	 getColumnClassName	java.lang.Integer
//    isAutoIncrement	false	 	 	 	 isNullable	1	 isSigned	true	 getColumnDisplaySize	11	 getColumnLabel	test_unique	 		getColumnName	test_unique	 		getSchemaName		 getPrecision	11	 getScale	0	 getTableName	interceptor	 	 getColumnType	4	 getColumnTypeName	INT	 			 	 	 getColumnClassName	java.lang.Integer
//    isAutoIncrement	false	 	 	 	 isNullable	1	 isSigned	true	 getColumnDisplaySize	11	 getColumnLabel	test_comment	 	getColumnName	test_comment	 	getSchemaName		 getPrecision	11	 getScale	0	 getTableName	interceptor	 	 getColumnType	4	 getColumnTypeName	INT	 	 		 	 	 getColumnClassName	java.lang.Integer
//    isAutoIncrement	false	 	 	 	 isNullable	1	 isSigned	false	 getColumnDisplaySize	500	 getColumnLabel	test_string_1000	getColumnName	test_string_1000	getSchemaName		 getPrecision	500	 getScale	0	 getTableName	interceptor	 	 getColumnType	12	 getColumnTypeName	VARCHAR	 		 	 	 getColumnClassName	java.lang.String
//    isAutoIncrement	false	 	 	 	 isNullable	1	 isSigned	true	 getColumnDisplaySize	4	 getColumnLabel	test_double	 		getColumnName	test_double	 		getSchemaName		 getPrecision	4	 getScale	2	 getTableName	interceptor	 	 getColumnType	8	 getColumnTypeName	DOUBLE	 		 	 	 getColumnClassName	java.lang.Double
    // 是否自增
    @ApiParam(value = "是否自增")
    private Integer isAutoIncrement;
    // 是否允许为空
    @ApiParam(value = "是否允许为空")
    private Integer isNullable;
    // 是否是对象
    @ApiParam(value = "是否是对象")
    private Integer isSigned;
    // 字段名称
    @ApiParam(value = "字段名称")
    private String columnName;
    // 字段长度
    @ApiParam(value = "字段长度")
    private Integer precision;
    // 字段精确长度
    @ApiParam(value = "字段精确长度")
    private Integer scale;

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

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

    // 字段类型编号
    @ApiParam(value = "字段类型编号")
    private Integer columnType;
    // 字段类型名称
    @ApiParam(value = "字段类型名称")
    private String columnTypeName;
    // 字段Java 类型
    @ApiParam(value = "字段Java 类型")
    private String columnClassName;
    // 字段Java 类型
    @ApiParam(value = "枚举:BlockFormEnumUtil.PROPERTY_TYPE")
    private Integer columnClassType;
    // 属性是否主键
    @ApiParam(value = "枚举: CommonEnumUtil.TRUE_OR_FALSE")
    private Integer columnPrimaryKey;

    @ApiParam(value = "属性值")
    private Object value;
    @ApiParam(value = "属性默认值")
    private Object defaultValue;

    public SqlColumnModel() {
    }

    public SqlColumnModel(String columnName, CommonEnumUtil.PROPERTY_TYPE type) {
        this.columnName = columnName;
        this.columnClassType = type.getValue();
        this.columnTypeName = type.getDescription();
    }
}
