using ProjectItCompany.Entities;
using ProjectItCompany.Entities.Enums;
using ProjectItCompany.Repositories;
using ProjectItCompany.Repositories.Implementations;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics.Tracing;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProjectItCompany.Forms
{
    public partial class FormWage : Form
    {
        private readonly IWageRepository _wageRepository;

        public FormWage(IWageRepository wageRepository, IExecutorRepository executorRepository)
        {
            InitializeComponent();
            _wageRepository = wageRepository ?? throw new ArgumentNullException(nameof(wageRepository));

            comboBoxExecutor.DataSource = executorRepository.ReadExecutors();
            comboBoxExecutor.DisplayMember = "FullName";
            comboBoxExecutor.ValueMember = "Id";

            comboBoxMonth.DataSource = Enum.GetValues(typeof(Month));
        }

        private void ButtonSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBoxExecutor.SelectedIndex < 0)
                {
                    throw new Exception("Имеются незаполненные поля");
                }
                _wageRepository.CreateWage(Wage.CreateOpeartion(0, (Month)comboBoxMonth.SelectedValue!, Convert.ToInt32(numericUpDownYear.Value), Convert.ToInt32(numericUpDownNumberOfHours.Value), (int)comboBoxExecutor.SelectedValue));
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка при сохранении",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void ButtonCancel_Click(object sender, EventArgs e) => Close();
    }

}

