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.util.Set;

/**
 * 问卷问题组实体类
 */
@Getter
@Setter
@Entity
@Table(name = "questionnaire_question_group")
@SQLDelete(sql = "UPDATE questionnaire_question_group SET deleted = true WHERE id=?")
@Where(clause = "deleted=false")
public class QuestionGroupEntity {

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

    // 所属问卷
    @ManyToOne
    @JoinColumn(name = "questionnaire_id")
    @NotNull
    private QuestionnaireEntity questionnaireEntity;

    // 问题组序号（用于排序）
    @NotNull
    private Integer no;

    // 问题组名
    @NotNull
    private String name;

    // 问题组下的所有问题
    @OneToMany(mappedBy = "questionGroupEntity", fetch = FetchType.EAGER)
    private Set<QuestionEntity> questionEntities;

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

}
