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

import cn.estsh.i3plus.pojo.aps.annotation.FieldAnnotation;
import cn.estsh.i3plus.pojo.aps.common.BaseAPS;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.holders.EImportDetail;
import cn.estsh.i3plus.pojo.aps.holders.EImportField;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @Description :数据导入明细
 * @Reference :
 * @Author : jason.niu
 * @CreateDate : 2019-09-23
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_IMPORT_FIELD")
@Api("数据导入字段配置")
public class ImportField extends BaseAPS {

    private static final long serialVersionUID = 8848879008582197564L;
    @Column(name="FIELD_NAME")
    @ApiParam("字段名")
    private String fieldName;

    @Column(name="LABEL_NAME")
    @ApiParam("标签名称")
    private String labelName;

    @Column(name="DEFAULT_VALUE")
    @ApiParam("默认值")
    private String defaultValue;

    /**
     *  1-是，2-否
     */
    @Column(name="IS_REQUIRE")
    @ApiParam(value = "是否必填", example = "0")
    private Integer isRequire;

    @Column(name="MAX_LENGTH")
    @ApiParam(value = "最大长度", example = "0")
    @FieldAnnotation(defaultValue = "255")
    private Integer maxLength;

    @Column(name="VALIDATOR")
    @ApiParam("校验表达式")
    private String validator;

    @Column(name="VALIDATOR_MESSAGE")
    @ApiParam("校验表达式报错")
    private String validatorMessage;

    @Column(name="RELATION_TABLE")
    @ApiParam("关联表名")
    private String relationTable;

    @Column(name="RELATION_FIELD")
    @ApiParam("关联字段")
    private String relationField;

    @Column(name="IMPORT_DETAIL_ID")
    @ApiParam(value ="导入明细ID")
    @FieldAnnotation(relation = "ImportDetail", notEmpty = true)
    private Long importDetailId;

    public ImportDetail getImportDetail() {
        return BeanRelation.get(this, EImportField.ImportDetail);
    }

    public void setImportDetail(ImportDetail detail) {
        this.importDetailId = detail != null ? detail.getId() : 0l;
        BeanRelation.set(this, EImportField.ImportDetail, detail);
    }
}
