using System.Threading.Tasks;
using Havit.Extensions.DependencyInjection.Abstractions;
using Microsoft.Extensions.Options;
using SendGrid;
using SendGrid.Helpers.Mail;

namespace DiplomovaPrace.Services.Mailer
{
	[Service]
	public class MailSenderService : IMailSenderService
	{
		private readonly MailerConfiguration mailerConfiguration;

		public MailSenderService(IOptions<MailerConfiguration> mailerConfiguration)
		{
			this.mailerConfiguration = mailerConfiguration.Value;
		}

		public async Task SendEmailAsync(SendGridMessage sendGridMessage)
		{
			SendGridClient client = new(mailerConfiguration.ApiKey);
			await client.SendEmailAsync(sendGridMessage).ConfigureAwait(false);
		}
	}
}
