using Microsoft.AspNetCore.Mvc;
using TravelCompanyContracts.BindingModels.TouristBindingModels;
using TravelCompanyContracts.BusinessLogicsContracts.TouristBusinessLogicsContracts;
using TravelCompanyContracts.SearchModels.TouristSearchModels;
using TravelCompanyContracts.ViewModels.TouristViewModels;

[Route("api/[controller]/[action]")]
[ApiController]
public class TouristController : Controller
{

    private readonly ILogger _logger;
    private readonly ITouristLogic _logic;

    public TouristController(ILogger<TouristController> logger, ITouristLogic logic)
    {
        _logger = logger;
        _logic = logic;
    }

    [HttpGet]
    public TouristViewModel? Login(string login, string password)
    {
        try
        {
            return _logic.ReadElement(new TouristSearchModel
            {
                Login = login,
                Password = password
            });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка входа в систему");
            return null;
        }
    }

    [HttpPost]
    public void Register(TouristBindingModel model)
    {
        try
        {
            _logic.Create(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка регистрации");
            throw;
        }
    }

    [HttpPost]
    public void UpdateData(TouristBindingModel model)
    {
        try
        {
            _logic.Update(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка обновления данных");
            throw;
        }
    }

}
