<?php


namespace App\Controllers;

use App\DAO\Filter\QueryFilter;
use App\DAO\Filter\QueryFilterTranslator;
use App\DAO\Order\QueryOrderTranslator;
use App\Services\DocumentoGeradoService;
use App\Services\ServiceResponse\ServiceResponseInterface;
use App\Utils\Collections\QueryFilterCollection;
use App\Utils\Collections\QueryOrderCollection;
use App\Validations\DocumentoGeradoValidation;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use Config\Paths;
use Exception;

class DocumentoGeradoController extends BaseController
{

    function getDocumentoGeradoList(){
        $pagination = $this->getPaginationFromRequest();
        $query_filter_collection = new QueryFilterCollection($_GET, QueryFilterTranslator::gerados());
        $query_order_collection = new QueryOrderCollection($_GET, QueryOrderTranslator::gerados());
        $procedimento_service_response = (new DocumentoGeradoService())->getDocumentoGeradoList($pagination, $query_filter_collection, $query_order_collection);
        $response_messages = [
            ServiceResponseInterface::SUCESS => [
                'code' => ResponseInterface::HTTP_OK,
                'message' => 'Os dados da galeria foram encontrados com sucesso.'
            ],
            ServiceResponseInterface::RECORD_NOT_FOUND => [
                'code' => ResponseInterface::HTTP_PARTIAL_CONTENT,
                'message' => 'Nenhum registro foi encontrado.'
            ],
            ServiceResponseInterface::SERVICE_INTERNAL_ERROR => [
                'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
                'message' => 'Erro interno do servidor.'
            ],
            ServiceResponseInterface::DATABASE_CONNECTION_ERROR => [
                'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
                'message' => 'Erro interno do servidor.'
            ],
        ];
        return $this->getResponse($procedimento_service_response, $response_messages);
    }

    public function searchDocumentoGeradoByID (int $id_arquivo) : Response {
        $query_filter = QueryFilter::builder()
            ->setTable('documentos_anexados')
            ->setNameParam('id')
            ->setValue($id_arquivo)
            ->setIsExact(true)
            ->build();
        $erro_service_response = (new DocumentoGeradoService())->getDocumentoGerado($query_filter);
        $response_messages = [
            ServiceResponseInterface::SUCESS => [
                'code' => ResponseInterface::HTTP_OK,
                'message' => 'O arquivo foi encontrado com sucesso.'
            ],
            ServiceResponseInterface::RECORD_NOT_FOUND => [
                'code' => ResponseInterface::HTTP_PARTIAL_CONTENT,
                'message' => 'Nenhum registro foi encontrado.'
            ],
            ServiceResponseInterface::SERVICE_INTERNAL_ERROR => [
                'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
                'message' => 'Erro interno do servidor.'
            ],
            ServiceResponseInterface::DATABASE_CONNECTION_ERROR => [
                'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
                'message' => 'Erro interno do servidor.'
            ],
        ];
        return $this->getResponse($erro_service_response, $response_messages);
    }


}
