using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;

namespace BankRestApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OperatorController : Controller
    {
        private readonly ILogger _logger;
        private readonly IOperatorLogic _operator;

        public OperatorController(ILogger<OperatorController> logger, IOperatorLogic operatorC)
        {
            _logger = logger;
            _operator = operatorC;
        }

        [HttpPost]
        public void CreateOperator(OperatorBindingModel model)
        {
            try
            {
                _operator.Create(model);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ошибка создания зачисления");
                throw;
            }
        }

        [HttpPatch]
        public void UpdateOperator(OperatorBindingModel model)
        {
            try
            {
                _operator.Update(model);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ошибка обновления зачисления");
                throw;
            }
        }
        [HttpDelete]
        public void DeleteOperator(int operatorId)
        {
            try
            {
                OperatorBindingModel model = new OperatorBindingModel
                {
                    Id = operatorId
                };
                _operator.Delete(model);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ошибка удаления зачисления");
                throw;
            }
        }
    }
}
