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

    private readonly ILogger _logger;
    private readonly IOperatorLogic _logic;

    public OperatorController(ILogger<OperatorController> logger, IOperatorLogic logic)
    {
        _logger = logger;
        _logic = logic;
    }

    [HttpGet]
    public List<OperatorViewModel>? GetOperators()
    {
        try
        {
            return _logic.ReadList(new OperatorSearchModel { });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка получения списка ");
            throw;
        }
    }
    [HttpGet]
    public OperatorViewModel? GetOperator(int touristId, int id)
    {
        try
        {
            return _logic.ReadElement(new OperatorSearchModel { Id=id });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка получения экскурсии клиента id={Id}", touristId);
            throw;
        }
    }
    [HttpPost]
    public void CreateOperator(OperatorBindingModel model)
    {
        try
        {
            _logic.Create(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка создания экскурсий");
            throw;
        }
    }
    [HttpPost]
    public void UpdateOperator(OperatorBindingModel model)
    {
        try
        {
            _logic.Update(model);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ошибка обновления экскурсии");
            throw;
        }
    }


}
