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

namespace OmsorgCore.Email;

public class UserInviteEmailComposer : IUserInviteEmailComposer
{
    private readonly EmailOptions _options;

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

    public EmailMessage Compose(string toEmail, string rawPin, int validityDays)
    {
        var template = _options.UserInviteTemplate;
        var values = new Dictionary<string, string>
        {
            ["INVITE_PIN"] = rawPin,
            ["INVITE_PIN_EXPIRY_DAYS"] = validityDays.ToString()
        };

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