namespace DramaLing.Api.Models.Configuration;

/// <summary>
/// 智能複習系統配置選項
/// </summary>
public class SpacedRepetitionOptions
{
    public const string SectionName = "SpacedRepetition";

    /// <summary>
    /// 間隔增長係數 (基於演算法規格書)
    /// </summary>
    public GrowthFactors GrowthFactors { get; set; } = new();

    /// <summary>
    /// 逾期懲罰係數
    /// </summary>
    public OverduePenalties OverduePenalties { get; set; } = new();

    /// <summary>
    /// 記憶衰減率 (每天百分比)
    /// </summary>
    public double MemoryDecayRate { get; set; } = 0.05;

    /// <summary>
    /// 最大間隔天數
    /// </summary>
    public int MaxInterval { get; set; } = 365;

    /// <summary>
    /// A1學習者保護門檻
    /// </summary>
    public int A1ProtectionLevel { get; set; } = 20;

    /// <summary>
    /// 新用戶預設程度
    /// </summary>
    public int DefaultUserLevel { get; set; } = 50;
}

/// <summary>
/// 間隔增長係數配置
/// </summary>
public class GrowthFactors
{
    /// <summary>
    /// 短期間隔係數 (≤7天)
    /// </summary>
    public double ShortTerm { get; set; } = 1.8;

    /// <summary>
    /// 中期間隔係數 (8-30天)
    /// </summary>
    public double MediumTerm { get; set; } = 1.4;

    /// <summary>
    /// 長期間隔係數 (31-90天)
    /// </summary>
    public double LongTerm { get; set; } = 1.2;

    /// <summary>
    /// 超長期間隔係數 (>90天)
    /// </summary>
    public double VeryLongTerm { get; set; } = 1.1;

    /// <summary>
    /// 根據當前間隔獲取增長係數
    /// </summary>
    /// <param name="currentInterval">當前間隔天數</param>
    /// <returns>對應的增長係數</returns>
    public double GetGrowthFactor(int currentInterval)
    {
        return currentInterval switch
        {
            <= 7 => ShortTerm,
            <= 30 => MediumTerm,
            <= 90 => LongTerm,
            _ => VeryLongTerm
        };
    }
}

/// <summary>
/// 逾期懲罰係數配置
/// </summary>
public class OverduePenalties
{
    /// <summary>
    /// 輕度逾期係數 (1-3天)
    /// </summary>
    public double Light { get; set; } = 0.9;

    /// <summary>
    /// 中度逾期係數 (4-7天)
    /// </summary>
    public double Medium { get; set; } = 0.75;

    /// <summary>
    /// 重度逾期係數 (8-30天)
    /// </summary>
    public double Heavy { get; set; } = 0.5;

    /// <summary>
    /// 極度逾期係數 (>30天)
    /// </summary>
    public double Extreme { get; set; } = 0.3;

    /// <summary>
    /// 根據逾期天數獲取懲罰係數
    /// </summary>
    /// <param name="overdueDays">逾期天數</param>
    /// <returns>對應的懲罰係數</returns>
    public double GetPenaltyFactor(int overdueDays)
    {
        return overdueDays switch
        {
            <= 0 => 1.0,    // 準時，無懲罰
            <= 3 => Light,   // 輕度逾期
            <= 7 => Medium,  // 中度逾期
            <= 30 => Heavy,  // 重度逾期
            _ => Extreme     // 極度逾期
        };
    }
}