namespace ROLAC.API.Services.Ai;

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

public sealed class ExpenseAiServiceFactory : IExpenseAiServiceFactory
{
    private readonly IChurchAiConfigProvider _config;
    private readonly ClaudeExpenseAiService _claude;
    private readonly GeminiExpenseAiService _gemini;

    public ExpenseAiServiceFactory(
        IChurchAiConfigProvider config,
        ClaudeExpenseAiService claude,
        GeminiExpenseAiService gemini)
    {
        _config = config;
        _claude = claude;
        _gemini = gemini;
    }

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