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.time.LocalDateTime;
import java.util.Objects;

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

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

    @Column(name = "u_id", columnDefinition = "varchar(36) not null comment '测试用户id'")
    private String uId;

    @Column(name = "is_complete", columnDefinition = "varchar(5) not null default 0 comment '当前用户测试计划是否已经完成：0---未完成，9---已完成'")
    private String isComplete;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "create_time", columnDefinition = "datetime not null  comment '记录创建时间'")
    private LocalDateTime 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 LocalDateTime updateTime;

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

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