package com.pharmacopoeia.entity;

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

import java.time.Instant;

@Entity
@Table(name = "knowledge_points")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class KnowledgePoint {

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

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

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

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

    @Column(name = "chapter_name", nullable = false, length = 256)
    private String chapterName;

    @Column(nullable = false, length = 512)
    private String title;

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

    @Column(nullable = false)
    private Integer difficulty;

    @Column(length = 16)
    private String frequency;

    @Column(name = "related_drugs", columnDefinition = "jsonb")
    private String relatedDrugs;

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

    @Column(name = "vector_id", length = 128)
    private String vectorId;

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

    @Column(name = "updated_at")
    private Instant updatedAt;

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

    @PreUpdate
    void preUpdate() {
        updatedAt = Instant.now();
    }
}
