using System.ComponentModel.DataAnnotations;

namespace DramaLing.Api.Models.Entities;

public class StudySession
{
    public Guid Id { get; set; }

    public Guid UserId { get; set; }

    [Required]
    [MaxLength(50)]
    public string SessionType { get; set; } = string.Empty; // flip, quiz, fill, listening, speaking

    public DateTime StartedAt { get; set; } = DateTime.UtcNow;

    public DateTime? EndedAt { get; set; }

    public int TotalCards { get; set; } = 0;

    public int CorrectCount { get; set; } = 0;

    public int DurationSeconds { get; set; } = 0;

    public int AverageResponseTimeMs { get; set; } = 0;

    // Navigation Properties
    public virtual User User { get; set; } = null!;
    public virtual ICollection<StudyRecord> StudyRecords { get; set; } = new List<StudyRecord>();
}

public class StudyRecord
{
    public Guid Id { get; set; }

    public Guid UserId { get; set; }

    public Guid FlashcardId { get; set; }

    public Guid SessionId { get; set; }

    [Required]
    [MaxLength(50)]
    public string StudyMode { get; set; } = string.Empty;

    [Range(1, 5)]
    public int QualityRating { get; set; }

    public int? ResponseTimeMs { get; set; }

    public string? UserAnswer { get; set; }

    public bool IsCorrect { get; set; }

    // SM-2 算法記錄
    public float PreviousEasinessFactor { get; set; }
    public float NewEasinessFactor { get; set; }
    public int PreviousIntervalDays { get; set; }
    public int NewIntervalDays { get; set; }
    public int PreviousRepetitions { get; set; }
    public int NewRepetitions { get; set; }
    public DateTime NextReviewDate { get; set; }

    public DateTime StudiedAt { get; set; } = DateTime.UtcNow;

    // Navigation Properties
    public virtual User User { get; set; } = null!;
    public virtual Flashcard Flashcard { get; set; } = null!;
    public virtual StudySession Session { get; set; } = null!;
}