package com.rf.psychological.plan.dao.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.rf.psychological.base.model.BaseEntity;
import lombok.*;
import org.hibernate.Hibernate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import java.util.Date;
import java.util.Objects;

/**
 * @author lpf
 * @description:
 * @date 2022/1/6 9:26
 */
@Entity
@ToString
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "t_test_plan_contend", indexes = {
        @Index(columnList = "id", unique = true),
        @Index(columnList = "test_id,flag"),
        @Index(columnList = "test_plan_id")
})
@org.hibernate.annotations.Table(appliesTo = "t_test_plan_contend", comment = "测试计划内容表")
public class TestPlanContendEntity extends BaseEntity {

    @Column(name = "test_plan_id", columnDefinition = "varchar(36) not null comment '测试计划id'")
    private String testPlanId;

    @Column(name = "test_id", columnDefinition = "varchar(50) not null comment '测试量表或者认知任务id（type:0--量表，1--认知任务）'")
    private String testId;

    @Column(name = "flag", columnDefinition = "varchar(50) null comment '测试量表或者认知任务flag（type:0--量表，1--认知任务）'")
    private String flag;

    @Column(name = "type", columnDefinition = "varchar(10) not null comment '测试条目类别：0---量表，1---认知任务'")
    private String type;

    @Column(name = "name", columnDefinition = "varchar(100)  comment '量表或认知任务名字'")
    private String name;

    @Column(name = "description", columnDefinition = "text  comment '量表或认知任务的描述语'")
    private String description;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "create_time", columnDefinition = "datetime not null  comment '记录创建时间'")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP comment '记录修改时间'")
    private Date updateTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        TestPlanContendEntity that = (TestPlanContendEntity) o;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
