namespace ROLAC.API.Services.Ai;

/// <summary>Selects the active category-AI provider per request from <c>ChurchProfile.AiProvider</c>.</summary>
public interface IExpenseCategoryAiServiceFactory
{
    Task<IExpenseCategoryAiService> ResolveAsync(CancellationToken ct = default);
}

public sealed class ExpenseCategoryAiServiceFactory : IExpenseCategoryAiServiceFactory
{
    private readonly IChurchAiConfigProvider _config;
    private readonly ClaudeExpenseCategoryAiService _claude;
    private readonly GeminiExpenseCategoryAiService _gemini;

    public ExpenseCategoryAiServiceFactory(
        IChurchAiConfigProvider config,
        ClaudeExpenseCategoryAiService claude,
        GeminiExpenseCategoryAiService gemini)
    {
        _config = config;
        _claude = claude;
        _gemini = gemini;
    }

    public async Task<IExpenseCategoryAiService> ResolveAsync(CancellationToken ct = default)
    {
        var cfg = await _config.GetAsync(ct);
        return cfg.Provider.Equals("Gemini", StringComparison.OrdinalIgnoreCase) ? _gemini : _claude;
    }
}
