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

    private readonly ILogger _logger;
    private readonly IExcursionLogic _logic;

    public ExcursionController(ILogger<ExcursionController> logger, IExcursionLogic logic)
    {
        _logger = logger;
        _logic = logic;
    }

    [HttpGet]
    public List<ExcursionViewModel>? GetExcursions(int touristId)
    {
        try
        {
            return _logic.ReadList(new ExcursionSearchModel { TouristId = touristId });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка получения списка экскурсий клиента id={Id}", touristId);
            throw;
        }
    }
    [HttpGet]
    public ExcursionViewModel? GetExcursion(int touristId, int id)
    {
        try
        {
            return _logic.ReadElement(new ExcursionSearchModel { TouristId = touristId, Id=id });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка получения экскурсии клиента id={Id}", touristId);
            throw;
        }
    }
    [HttpPost]
    public void CreateExcursion(ExcursionBindingModel model)
    {
        try
        {
            _logic.Create(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка создания экскурсий");
            throw;
        }
    }
    [HttpPost]
    public void UpdateExcursion(ExcursionBindingModel model)
    {
        try
        {
            _logic.Update(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка обновления экскурсии");
            throw;
        }
    }
    [HttpPost]
    public void DeleteExcursion(ExcursionBindingModel model)
    {
        try
        {
            _logic.Delete(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка удаления экскурсии");
            throw;
        }
    }

}
