using Microsoft.Extensions.Logging;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.ViewModels;

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

        private void LoadData()
        {
            try
            {
                dataGridView.FillAndConfigGrid(messageInfoLogic.ReadList(null));
                logger.LogInformation("Load list of mails");

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK);
                logger.LogError("Load list of mails failed");
            }
        }

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