using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.ViewModels;

namespace VetClinicRestApi.Controllers
{
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class PharmacistController : Controller
	{
		private readonly ILogger _logger;
		private readonly IPharmacistLogic _logic;
		public PharmacistController(IPharmacistLogic logic, ILogger<PharmacistController>
	   logger)
		{
			_logger = logger;
			_logic = logic;
		}
		[HttpGet]
		public PharmacistViewModel? Login(string email, string password)
		{
			try
			{
				return _logic.ReadElement(new PharmacistSearchModel
				{
					Email = email,
					Password = password
				});
			}
			catch (Exception ex)
			{
				_logger.LogError(ex, "Ошибка входа в систему");
				throw;
			}
		}
		[HttpPost]
		public void Register(PharmacistBindingModel model)
		{
			try
			{
				_logic.Create(model);
			}
			catch (Exception ex)
			{
				_logger.LogError(ex, "Ошибка регистрации");
				throw;
			}
		}
		[HttpPost]
		public void UpdateData(PharmacistBindingModel model)
		{
			try
			{
				_logic.Update(model);
			}
			catch (Exception ex)
			{
				_logger.LogError(ex, "Ошибка обновления данных");
				throw;
			}
		}

	}
}
