package com.pharmacopoeia.entity;

import jakarta.persistence.*;
import lombok.*;

import java.time.Instant;

@Entity
@Table(name = "questions")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Question {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "question_id", unique = true, nullable = false, length = 64)
    private String questionId;

    @Column(name = "question_type", nullable = false, length = 8)
    private String questionType;

    @Column(nullable = false, length = 64)
    private String subject;

    @Column(name = "chapter_id", nullable = false, length = 64)
    private String chapterId;

    @Column(nullable = false)
    private Integer difficulty;

    @Column(columnDefinition = "text", nullable = false)
    private String content;

    @Column(columnDefinition = "jsonb", nullable = false)
    private String options;

    @Column(nullable = false, length = 16)
    private String answer;

    @Column(columnDefinition = "text", nullable = false)
    private String explanation;

    @Column(name = "knowledge_point_ids", columnDefinition = "jsonb")
    private String knowledgePointIds;

    @Column(columnDefinition = "text")
    private String source;

    @Column(length = 16)
    private String frequency;

    @Builder.Default
    @Column(nullable = false)
    private Boolean audited = false;

    @Builder.Default
    @Column(name = "correct_count", nullable = false)
    private Integer correctCount = 0;

    @Builder.Default
    @Column(name = "attempt_count", nullable = false)
    private Integer attemptCount = 0;

    @Column(name = "created_at")
    private Instant createdAt;

    @PrePersist
    void prePersist() {
        createdAt = Instant.now();
    }
}
