<?php

namespace App\Controllers;

use App\Controllers\BaseController;
use App\Services\CreditoClienteService;
use App\Services\ServiceResponse\ServiceResponseInterface;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use App\Services\JWT\UsuarioLogado;

class CreditoClienteController extends BaseController {

	public function getCreditoByClienteIdByUnidadeId(int $clientid, int $unidadeid):Response {
		
		$usuarioid = UsuarioLogado::getUsuarioId();
		$credidocliente_service = new CreditoClienteService();
		$service_response = $credidocliente_service->getCreditoByClienteIdByUnidadeId($clientid, $unidadeid, $usuarioid);
		
		
		
		$response_messages = [
				ServiceResponseInterface::SUCESS => [
						'code' => ResponseInterface::HTTP_OK,
						'message' => 'O procedimento foi cadastrado com sucesso.'
				],
				ServiceResponseInterface::RECORD_NOT_FOUND => [
						'code' => ResponseInterface::HTTP_PARTIAL_CONTENT,
						'message' => 'Nenhum registro foi encontrado.'
				],
				ServiceResponseInterface::FORBIDDEN => [
						'code' => ResponseInterface::HTTP_FORBIDDEN,
						'message' => 'Acesso negado psrs pesquisa na unidade informada.'
				],
				ServiceResponseInterface::DATABASE_CONNECTION_ERROR => [
						'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
						'message' => 'Erro de conexão com o banco de dados.'
				],				
				ServiceResponseInterface::VALIDATION_PARAMS_ERROR => [
						'code' => ResponseInterface::HTTP_BAD_REQUEST,
						'message' => 'Informe os dados corretamente.'
				],				
				ServiceResponseInterface::SERVICE_INTERNAL_ERROR => [
						'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
						'message' => 'Erro interno do servidor.'
				]
		];
		
		return $this->getResponse ( $service_response, $response_messages );
	}

}

