using Microsoft.AspNetCore.Identity;

namespace Indotalent.Infrastructure.Email;

public class IdentityEmailManager<TUser> : IEmailSender<TUser> where TUser : class
{
    private readonly IEmailSender _emailSender;

    public IdentityEmailManager(IEmailSender emailSender)
    {
        _emailSender = emailSender;
    }

    public Task SendConfirmationLinkAsync(TUser user, string email, string confirmationLink)
    {
        var message = confirmationLink.Contains("<")
            ? confirmationLink
            : $"Please confirm your account by clicking this link: <a href='{confirmationLink}'>Confirm Account</a>";

        return _emailSender.SendEmailAsync(email, "Account Confirmation", message);
    }

    public Task SendPasswordResetLinkAsync(TUser user, string email, string resetLink)
    {
        var message = resetLink.Contains("<")
            ? resetLink
            : $"To reset your password, please click the following link: <a href='{resetLink}'>Reset Password</a>";

        return _emailSender.SendEmailAsync(email, "Password Reset Request", message);
    }

    public Task SendPasswordResetCodeAsync(TUser user, string email, string resetCode) =>
        _emailSender.SendEmailAsync(email, "Your Password Reset Code",
            $"Your password reset security code is: <b>{resetCode}</b>. Please enter this code to proceed with the reset process.");
}