using Codex.Dal.QueryProviders;
using Microsoft.Extensions.DependencyInjection;
using OpenHarbor.CQRS;

namespace Codex.Dal;

public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddQueryableProviderOverride<T, TService>(this IServiceCollection services)
      where TService : class, IQueryableProviderOverride<T>
    {
        return services.AddTransient<IQueryableProviderOverride<T>, TService>();
    }

    /// <summary>
    /// Registers all dynamic queries (paginated queries)
    /// </summary>
    public static IServiceCollection AddDynamicQueries(this IServiceCollection services)
    {
        // Agent list query
        services.AddQueryableProviderOverride<ListAgentsQueryItem, ListAgentsQueryableProvider>();

        // Agent execution list query
        services.AddQueryableProviderOverride<ListAgentExecutionsQueryItem, ListAgentExecutionsQueryableProvider>();

        // Conversation list query
        services.AddQueryableProviderOverride<ListConversationsQueryItem, ListConversationsQueryableProvider>();

        return services;
    }
}
