using SecureShopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SecureShopView
{
    public partial class FormMessages : Form
    {
        private readonly ILogger _logger;
        private readonly IMessageInfoLogic _logic;

        public FormMessages(ILogger<FormSecures> logger, IMessageInfoLogic logic)
        {
            InitializeComponent();
            _logger = logger;
            _logic = logic;
        }

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

        private void LoadData()
        {
            try
            {
                var list = _logic.ReadList(null);
                if (list != null)
                {
                    dataGridView.DataSource = list;
                    dataGridView.Columns["ClientId"].Visible = false;
                    dataGridView.Columns["MessageId"].Visible = false;
                    dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                }
                _logger.LogInformation("Загрузка сообщений");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ошибка загрузки сообщений");
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
