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 TravelController : Controller
{

    private readonly ILogger _logger;
    private readonly ITravelLogic _logic;

    public TravelController(ILogger<TravelController> logger, ITravelLogic logic)
    {
        _logger = logger;
        _logic = logic;
    }

    [HttpGet]
    public List<TravelViewModel>? GetTravels(int touristId)
    {
        try
        {
            return _logic.ReadList(new TravelSearchModel { TouristId = touristId });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка получения списка путешествий клиента id={Id}", touristId);
            throw;
        }
    }
    [HttpPost]
    public void CreateTravel(TravelBindingModel model)
    {
        try
        {
            _logic.Create(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка создания путешествия");
            throw;
        }
    }
    [HttpPost]
    public void UpdateTravel(TravelBindingModel model)
    {
        try
        {
            _logic.Update(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка обновления путешествия");
            throw;
        }
    }
    [HttpPost]
    public void DeleteTravel(TravelBindingModel model)
    {
        try
        {
            _logic.Delete(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка удаления путешествия");
            throw;
        }
    }

}
