using Microsoft.Extensions.DependencyInjection;

namespace ZB.MOM.WW.ScadaBridge.NotificationService;

public static class ServiceCollectionExtensions
{
    /// <summary>
    /// Registers the shared SMTP delivery primitives consumed by the central Notification
    /// Outbox's <c>EmailNotificationDeliveryAdapter</c>: <see cref="NotificationOptions"/>,
    /// <see cref="OAuth2TokenService"/>, and the <see cref="ISmtpClientWrapper"/> factory.
    /// Central-only — sites no longer deliver notifications (see
    /// <c>Component-NotificationService.md</c>), and the orphaned site-shaped
    /// <c>NotificationDeliveryService</c> + <c>INotificationDeliveryService</c> contract
    /// was removed (NS-019). Notification dispatch lives in <c>ZB.MOM.WW.ScadaBridge.NotificationOutbox</c>.
    /// </summary>
    /// <param name="services">The service collection to register into.</param>
    /// <returns>The same <paramref name="services"/> collection, for chaining.</returns>
    public static IServiceCollection AddNotificationService(this IServiceCollection services)
    {
        services.AddOptions<NotificationOptions>()
            .BindConfiguration("ScadaBridge:Notification");

        services.AddHttpClient();
        services.AddSingleton<OAuth2TokenService>();
        services.AddSingleton<Func<ISmtpClientWrapper>>(_ => () => new MailKitSmtpClientWrapper());

        return services;
    }

    /// <summary>
    /// Registers Akka.NET actors for the notification service (placeholder for actor registration).
    /// </summary>
    /// <param name="services">The service collection to register into.</param>
    /// <returns>The same <paramref name="services"/> collection, for chaining.</returns>
    public static IServiceCollection AddNotificationServiceActors(this IServiceCollection services)
    {
        // Actor registration happens in AkkaHostedService.
        return services;
    }
}
