using KiMailOrderAgent.Models;
using KiMailOrderAgent.Settings;
using Microsoft.Extensions.Options;

namespace KiMailOrderAgent.Mail;

public class MailPreFilter
{
    private readonly MailFilterSettings _settings;

    public MailPreFilter(IOptions<MailFilterSettings> options)
    {
        _settings = options.Value;
    }

    public bool IsAllowedSender(IncomingMail mail)
    {
        if (_settings.AllowedSenders.Count == 0)
            return false;

        var from = mail.From.ToLowerInvariant();

        return _settings.AllowedSenders.Any(allowed =>
            from.Contains(allowed.ToLowerInvariant()));
    }
}