using DramaLing.Api.Models.DTOs;

namespace DramaLing.Api.Services;

/// <summary>
/// 分析服務介面，封裝 AI 分析的業務邏輯
/// </summary>
public interface IAnalysisService
{
    /// <summary>
    /// 智能分析英文句子，包含快取策略
    /// </summary>
    /// <param name="inputText">輸入文本</param>
    /// <param name="options">分析選項</param>
    /// <returns>分析結果</returns>
    Task<SentenceAnalysisData> AnalyzeSentenceAsync(string inputText, AnalysisOptions options);

    /// <summary>
    /// 檢查快取是否存在
    /// </summary>
    /// <param name="inputText">輸入文本</param>
    /// <param name="options">分析選項</param>
    /// <returns>是否有快取</returns>
    Task<bool> HasCachedAnalysisAsync(string inputText, AnalysisOptions options);

    /// <summary>
    /// 清除特定分析的快取
    /// </summary>
    /// <param name="inputText">輸入文本</param>
    /// <param name="options">分析選項</param>
    /// <returns>是否成功</returns>
    Task<bool> ClearAnalysisCacheAsync(string inputText, AnalysisOptions options);

    /// <summary>
    /// 取得分析統計資訊
    /// </summary>
    /// <returns>統計資訊</returns>
    Task<AnalysisStats> GetAnalysisStatsAsync();
}

/// <summary>
/// 分析統計資訊
/// </summary>
public class AnalysisStats
{
    public int TotalAnalyses { get; set; }
    public int CachedAnalyses { get; set; }
    public double CacheHitRate => TotalAnalyses > 0 ? (double)CachedAnalyses / TotalAnalyses : 0;
    public int AverageResponseTimeMs { get; set; }
    public DateTime LastAnalysisAt { get; set; }
    public Dictionary<string, int> ProviderUsageStats { get; set; } = new();
}