using Microsoft.Extensions.DependencyInjection;

namespace ScadaLink.SiteEventLogging;

public static class ServiceCollectionExtensions
{
    /// <summary>
    /// Register site event logging services (recording, purge, query).
    /// </summary>
    public static IServiceCollection AddSiteEventLogging(this IServiceCollection services)
    {
        // The recorder is registered as a concrete singleton and the interface is
        // forwarded to the same instance. The purge and query services depend on the
        // concrete SiteEventLogger directly (they need its lock-guarded WithConnection)
        // rather than downcasting an ISiteEventLogger, which would throw
        // InvalidCastException for any other ISiteEventLogger implementation.
        services.AddSingleton<SiteEventLogger>();
        services.AddSingleton<ISiteEventLogger>(sp => sp.GetRequiredService<SiteEventLogger>());
        services.AddSingleton<IEventLogQueryService, EventLogQueryService>();
        services.AddHostedService<EventLogPurgeService>();
        return services;
    }

    public static IServiceCollection AddSiteEventLoggingActors(this IServiceCollection services)
    {
        // Placeholder for Akka actor registration (Phase 4+)
        return services;
    }
}
