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

    private readonly ILogger _logger;
    private readonly IPlaceLogic _logic;

    public PlaceController(ILogger<PlaceController> logger, IPlaceLogic logic)
    {
        _logger = logger;
        _logic = logic;
    }

    [HttpGet]
    public List<PlaceViewModel>? GetPlaces(int touristId)
    {
        try
        {
            return _logic.ReadList(new PlaceSearchModel { TouristId = touristId });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка получения списка мест клиента id={Id}", touristId);
            throw;
        }
    }
    [HttpPost]
    public void CreatePlace(PlaceBindingModel model)
    {
        try
        {
            _logic.Create(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка создания мест");
            throw;
        }
    }
    [HttpPost]
    public void UpdatePlace(PlaceBindingModel model)
    {
        try
        {
            _logic.Update(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка обновления мест");
            throw;
        }
    }
    [HttpPost]
    public void DeletePlace(PlaceBindingModel model)
    {
        try
        {
            _logic.Delete(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка обновления мест");
            throw;
        }
    }

}
