using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using OmsorgCore.Application.Abstractions;

namespace OmsorgCore.Email;

public static class DependencyInjection
{
    public static IServiceCollection AddEmail(this IServiceCollection services, IConfiguration configuration)
    {
        services.Configure<EmailOptions>(configuration.GetSection(EmailOptions.SectionName));

        var provider = configuration.GetSection(EmailOptions.SectionName)["Provider"];
        if (string.Equals(provider, "Smtp", StringComparison.OrdinalIgnoreCase))
        {
            services.AddScoped<IEmailSender, SmtpEmailSender>();
        }
        else
        {
            services.AddScoped<IEmailSender, ConsoleEmailSender>();
        }

        services.AddScoped<IPasswordResetEmailComposer, PasswordResetEmailComposer>();
        services.AddScoped<IUserInviteEmailComposer, UserInviteEmailComposer>();

        return services;
    }
}
