<?php

namespace App\Controllers;

use App\DAO\Filter\QueryFilterTranslator;
use App\DAO\Order\QueryOrder;
use App\DAO\Order\QueryOrderTranslator;
use App\Services\DashboardService;
use App\Services\ServiceResponse\ServiceResponseInterface;
use App\Utils\Collections\QueryFilterCollection;
use App\Utils\Collections\QueryOrderCollection;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;

class DashboardController extends BaseController {

	public function getDashboardByMedicoID(int $id_medico): Response {

		$query_filter_collection = new QueryFilterCollection( $_GET, QueryFilterTranslator::dashboard() );
		$query_order_collection = new QueryOrderCollection( $_GET, QueryOrderTranslator::dashboard() );
		$dashboard_service_response = (new DashboardService())->getDashboardMedico( $id_medico, $query_filter_collection, $query_order_collection );
		$response_messages = [ 
			ServiceResponseInterface::SUCESS => [ 
				'code' => ResponseInterface::HTTP_OK,
				'message' => 'Os dados do dashboard 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( $dashboard_service_response, $response_messages );

	}

    public function getDashboardByMedicoIdTelevet(int $id_medico): Response {

        $query_filter_collection = new QueryFilterCollection( $_GET, QueryFilterTranslator::dashboard_televet() );
        $query_order_collection = new QueryOrderCollection( $_GET, QueryOrderTranslator::dashboard() );
        $dashboard_service_response = (new DashboardService())->getDashboardMedicoTelevet( $id_medico, $query_filter_collection, $query_order_collection );
        $response_messages = [
            ServiceResponseInterface::SUCESS => [
                'code' => ResponseInterface::HTTP_OK,
                'message' => 'Os dados do dashboard 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( $dashboard_service_response, $response_messages );

    }

	public function getDashboardByPacienteID(int $id_paciente): Response {

		$dashboard_service_response = (new DashboardService())->getDashboardPaciente( $id_paciente );
		$response_messages = [ 
			ServiceResponseInterface::SUCESS => [ 
				'code' => ResponseInterface::HTTP_OK,
				'message' => 'Os dados do dashboard foram encontrados com sucesso.' ],
			ServiceResponseInterface::RECORD_NOT_FOUND => [ 
				'code' => ResponseInterface::HTTP_PARTIAL_CONTENT,
				'message' => 'Nenhum registro foi encontrado.' ],
			ServiceResponseInterface::FORBIDDEN => [ 
				'code' => ResponseInterface::HTTP_FORBIDDEN,
				'message' => 'Esse usuário não tem permissão para realizar essa operação.' ],
			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( $dashboard_service_response, $response_messages );

	}

}