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

namespace TakeoutSaaS.Application.Sms.Extensions;

/// <summary>
/// 短信应用服务注册扩展。
/// </summary>
public static class SmsServiceCollectionExtensions
{
    /// <summary>
    /// 注册短信验证码应用服务。
    /// </summary>
    public static IServiceCollection AddSmsApplication(this IServiceCollection services, IConfiguration configuration)
    {
        services.AddOptions<VerificationCodeOptions>()
            .Bind(configuration.GetSection("Sms:VerificationCode"))
            .ValidateDataAnnotations()
            .ValidateOnStart();

        services.AddScoped<IVerificationCodeService, VerificationCodeService>();
        return services;
    }
}
