using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using TakeoutSaaS.Module.Sms.Abstractions;
using TakeoutSaaS.Module.Sms.Models;
using TakeoutSaaS.Module.Sms.Options;

namespace TakeoutSaaS.Module.Sms.Services;

/// <summary>
/// 阿里云短信发送实现（简化版，占位可扩展正式签名流程）。
/// </summary>
public sealed class AliyunSmsSender(IHttpClientFactory httpClientFactory, IOptionsMonitor<SmsOptions> optionsMonitor, ILogger<AliyunSmsSender> logger)
    : ISmsSender
{
    /// <inheritdoc />
    public SmsProviderKind Provider => SmsProviderKind.Aliyun;

    /// <inheritdoc />
    public Task<SmsSendResult> SendAsync(SmsSendRequest request, CancellationToken cancellationToken = default)
    {
        var options = optionsMonitor.CurrentValue;
        if (options.UseMock)
        {
            logger.LogInformation("Mock 发送阿里云短信到 {Phone}, Template:{Template}", request.PhoneNumber, request.TemplateCode);
            return Task.FromResult(new SmsSendResult { Success = true, Message = "Mocked" });
        }
        // 预留 HttpClient，便于后续接入阿里云正式签名请求
        using var httpClient = httpClientFactory.CreateClient(nameof(AliyunSmsSender));

        // 占位：保留待接入阿里云正式签名流程，当前返回未实现。
        logger.LogWarning("阿里云短信尚未启用，请配置腾讯云或开启 UseMock。");
        return Task.FromResult(new SmsSendResult { Success = false, Message = "Aliyun SMS not enabled" });
    }
}
