using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TakeoutSaaS.Module.Sms.Abstractions;
using TakeoutSaaS.Module.Sms.Options;
using TakeoutSaaS.Module.Sms.Services;

namespace TakeoutSaaS.Module.Sms.Extensions;

/// <summary>
/// 短信模块 DI 注册扩展。
/// </summary>
public static class SmsServiceCollectionExtensions
{
    /// <summary>
    /// 注册短信模块（包含腾讯云、阿里云实现）。
    /// </summary>
    public static IServiceCollection AddSmsModule(this IServiceCollection services, IConfiguration configuration)
    {
        services.AddOptions<SmsOptions>()
            .Bind(configuration.GetSection("Sms"))
            .ValidateDataAnnotations()
            .ValidateOnStart();

        services.AddHttpClient(nameof(TencentSmsSender));
        services.AddHttpClient(nameof(AliyunSmsSender));

        services.AddSingleton<ISmsSender, TencentSmsSender>();
        services.AddSingleton<ISmsSender, AliyunSmsSender>();
        services.AddSingleton<ISmsSenderResolver, SmsSenderResolver>();

        return services;
    }
}
