using Microsoft.Extensions.Logging;
using SecuritySystemBusinessLogic.BusinessLogics;
using SecuritySystemContracts.BusinessLogicsContracts;

namespace SecuritySystemView.Mail
{
    public partial class FormMails : Form
    {
        private readonly ILogger _logger;
        private readonly IMessageInfoLogic _logic;
        public FormMails(ILogger<FormMails> logger, IMessageInfoLogic messageInfoLogic)
        {
            InitializeComponent();
            _logger = logger;
            _logic = messageInfoLogic;
        }

        private void FormMails_Load(object sender, EventArgs e)
        {
            LoadData();
        }
        private void LoadData()
        {
            try
            {
                dataGridView.FillandConfigGrid(_logic.ReadList(null));
                _logger.LogInformation("Загрузка почты");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ошибка загрузки почты");
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
            }
        }

        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            LoadData();
        }
    }
}
