package com.pharmacopoeia.entity;

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

import java.time.Instant;

@Entity
@Table(name = "user_progress")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UserProgress {

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

    @Column(name = "user_id", nullable = false)
    private Long userId;

    @Column(length = 64)
    private String subject;

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

    @Column(name = "knowledge_point_id", length = 64)
    private String knowledgePointId;

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

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

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

    @Column(name = "last_study_at")
    private Instant lastStudyAt;

    @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();
    }
}
