<?php


namespace App\Controllers;

use App\DAO\Filter\QueryFilter;
use App\DAO\Filter\QueryFilterTranslator;
use App\DAO\Order\QueryOrderTranslator;
use App\DAO\PacienteDAO;
use App\Services\AdendoService;
use App\Services\PacienteService;
use App\Services\ServiceResponse\ServiceResponseInterface;
use App\Utils\Collections\QueryFilterCollection;
use App\Utils\Collections\QueryOrderCollection;
use App\Validations\PacienteValidation;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Model;

class AdendoController extends BaseController
{

    public function register(): Response
    {
        if (!isset($_POST["consulta_id"]) || !isset($_POST["descricao"]) ) {
            return $this->response->setJSON([
                'message' => 'Informe os dados corretamente.',
            ]);
        }

        $_POST["data"] = date("Y-m-d");
        $_POST["hora"] = date("H:i");

        $data_post = $_POST;
        $adendo_service_response = (new AdendoService())->registerAdendo($data_post);
        $response_messages = [
            ServiceResponseInterface::DATABASE_CONNECTION_ERROR => [
                'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
                'message' => 'Erro de conexão com o banco de dados.'
            ],
            ServiceResponseInterface::SUCESS => [
                'code' => ResponseInterface::HTTP_OK,
                'message' => 'Adendo criado com sucesso.'
            ],
            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($adendo_service_response, $response_messages);
    }

    public function getAdendoListByConsultaId(int $consulta_id): Response
    {
        $adendo_service_response = (new AdendoService())->getAdendoListByConsultaId($consulta_id);
        $response_messages = [
            ServiceResponseInterface::DATABASE_CONNECTION_ERROR => [
                'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
                'message' => 'Erro de conexão com o banco de dados.'
            ],
            ServiceResponseInterface::SUCESS => [
                'code' => ResponseInterface::HTTP_OK,
                'message' => 'Adendo criado com sucesso.'
            ],
            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($adendo_service_response, $response_messages);
    }

}
