using Microsoft.Extensions.DependencyInjection;
using ScadaLink.Commons.Interfaces.Services;

namespace ScadaLink.NotificationService;

public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddNotificationService(this IServiceCollection services)
    {
        services.AddOptions<NotificationOptions>()
            .BindConfiguration("ScadaLink:Notification");

        services.AddHttpClient();
        services.AddSingleton<OAuth2TokenService>();
        services.AddSingleton<Func<ISmtpClientWrapper>>(_ => () => new MailKitSmtpClientWrapper());
        services.AddScoped<NotificationDeliveryService>();
        services.AddScoped<INotificationDeliveryService>(sp => sp.GetRequiredService<NotificationDeliveryService>());

        return services;
    }

    public static IServiceCollection AddNotificationServiceActors(this IServiceCollection services)
    {
        // Actor registration happens in AkkaHostedService.
        return services;
    }
}
