using Microsoft.Extensions.Options;
using OmsorgCore.Application.Abstractions;

namespace OmsorgCore.Email;

public class PasswordResetEmailComposer : IPasswordResetEmailComposer
{
    private readonly EmailOptions _options;

    public PasswordResetEmailComposer(IOptions<EmailOptions> options)
    {
        _options = options.Value;
    }

    public EmailMessage Compose(string toEmail, string rawPin)
    {
        var template = _options.PasswordResetTemplate;
        var values = new Dictionary<string, string>
        {
            ["RESET_PIN"] = rawPin,
            ["RESET_PIN_EXPIRY_MINUTES"] = _options.PinExpiryMinutes.ToString()
        };

        return new EmailMessage(
            toEmail,
            EmailTemplateRenderer.Render(template.Subject, values),
            EmailTemplateRenderer.Render(template.BodyTemplate, values),
            FromAccountKey: _options.PasswordResetAccount);
    }
}
