using Microsoft.AspNetCore.Mvc;
using TravelCompanyContracts.BindingModels.OperatorBindingModels;
using TravelCompanyContracts.BindingModels.TouristBindingModels;
using TravelCompanyContracts.BusinessLogicsContracts.OperatorBusinessLogicsContracts;
using TravelCompanyContracts.BusinessLogicsContracts.TouristBusinessLogicsContracts;
using TravelCompanyContracts.SearchModels.OperatorSearchModels;
using TravelCompanyContracts.SearchModels.TouristSearchModels;
using TravelCompanyContracts.ViewModels.OperatorViewModels;
using TravelCompanyContracts.ViewModels.TouristViewModels;

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

    private readonly ILogger _logger;
    private readonly ITourLogic _logic;

    public TourController(ILogger<TourController> logger, ITourLogic logic)
    {
        _logger = logger;
        _logic = logic;
    }

    [HttpGet]
    public List<TourViewModel>? GetTours()
    {
        try
        {
            return _logic.ReadList(null);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка получения списка туров");
            throw;
        }
    }
    [HttpGet]
    public TourViewModel? GetTour(int id)
    {
        try
        {
            return _logic.ReadElement(new TourSearchModel {  Id=id });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка получения тура");
            throw;
        }
    }
    [HttpPost]
    public void CreateTour(TourBindingModel model)
    {
        try
        {
            _logic.Create(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка создания тура");
            throw;
        }
    }
    
    [HttpPost]
    public void DeleteTour(TourBindingModel model)
    {
        try
        {
            _logic.Delete(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка удаления тура");
            throw;
        }
    }

}
