package com.cirle.scientific.questionnaire.entity;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.Set;

/**
 * 问卷实体类
 */
@Getter
@Setter
@Entity // 实体类
@Table(name = "questionnaire") // 实体对应的数据库表名
@SQLDelete(sql = "UPDATE questionnaire SET deleted = true WHERE id=?") // 重写实体删除实现，将默认的物理删除改为逻辑软删除
@Where(clause = "deleted=false") // 忽略已删除的记录
public class QuestionnaireEntity {

    // ID：实体的唯一标识，不建议用于业务用途
    @Id
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    @NotNull
    private String id;

    // 问卷名
    @NotNull
    private String name;

    // 问卷备注
    private String remark;

    // 问卷所有问题组
    @OneToMany(mappedBy = "questionnaireEntity", fetch = FetchType.EAGER)
    private Set<QuestionGroupEntity> questionGroupEntities;

    // 创建时间
    @NotNull
    private LocalDateTime createTime;

    // 上次修改时间
    private LocalDateTime lastModifiedTime;

    // 逻辑删除标识
    @NotNull
    private Boolean deleted = Boolean.FALSE;

}