using DramaLing.Api.Models.DTOs;

namespace DramaLing.Api.Services.AI;

/// <summary>
/// AI 提供商抽象介面，支援多個 AI 服務提供商
/// </summary>
public interface IAIProvider
{
    /// <summary>
    /// 提供商名稱
    /// </summary>
    string ProviderName { get; }

    /// <summary>
    /// 提供商是否可用
    /// </summary>
    bool IsAvailable { get; }

    /// <summary>
    /// 每次請求的大概成本（用於選擇策略）
    /// </summary>
    decimal CostPerRequest { get; }

    /// <summary>
    /// 支援的最大輸入長度
    /// </summary>
    int MaxInputLength { get; }

    /// <summary>
    /// 平均響應時間（毫秒）
    /// </summary>
    int AverageResponseTimeMs { get; }

    /// <summary>
    /// 分析英文句子
    /// </summary>
    /// <param name="inputText">輸入文本</param>
    /// <param name="options">分析選項</param>
    /// <returns>分析結果</returns>
    Task<SentenceAnalysisData> AnalyzeSentenceAsync(string inputText, AnalysisOptions options);

    /// <summary>
    /// 檢查提供商健康狀態
    /// </summary>
    /// <returns>健康狀態</returns>
    Task<AIProviderHealthStatus> CheckHealthAsync();

    /// <summary>
    /// 取得提供商使用統計
    /// </summary>
    /// <returns>使用統計</returns>
    Task<AIProviderStats> GetStatsAsync();
}

/// <summary>
/// AI 提供商健康狀態
/// </summary>
public class AIProviderHealthStatus
{
    public bool IsHealthy { get; set; }
    public string? ErrorMessage { get; set; }
    public DateTime CheckedAt { get; set; }
    public int ResponseTimeMs { get; set; }
}

/// <summary>
/// AI 提供商使用統計
/// </summary>
public class AIProviderStats
{
    public int TotalRequests { get; set; }
    public int SuccessfulRequests { get; set; }
    public int FailedRequests { get; set; }
    public double SuccessRate => TotalRequests > 0 ? (double)SuccessfulRequests / TotalRequests : 0;
    public int AverageResponseTimeMs { get; set; }
    public DateTime LastUsedAt { get; set; }
    public decimal TotalCost { get; set; }
}