<?php

namespace app\Controllers;

use App\Controllers\BaseController;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use App\Services\ChameFacilService;
use App\Services\ServiceResponse\ServiceResponseInterface;

class ChameFacilController extends BaseController {

	public function registerSenhaChamar(): Response {
		
		$cf_service = new ChameFacilService();
		if (!$cf_service->validrequestSenhaChamar( $_POST )) {
			return $this->response->setStatusCode( 400 )
			->setJSON( [
					'message' => 'Dados invalidos, revisar os dados.',
					'data' => [ ]
			] );
		}
		$cf_response = $cf_service->registerRecepcaoSenha( $_POST,'Encaminhar','Recepção' );
		$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' => 'Os dados do consulta foram atualizados 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 ( $cf_response, $response_messages );
		
		
	}
	
	public function registerRecepcaoSenhaEncaminhar(): Response {

		$cf_service = new ChameFacilService();
		if (!$cf_service->validrequestRecepcaoEncaminhar( $_POST )) {
			return $this->response->setStatusCode( 400 )
				->setJSON( [ 
				'message' => 'Dados invalidos, revisar os dados.',
				'data' => [ ]
			] );
		}
		$cf_response = $cf_service->registerRecepcaoSenha( $_POST,'Encaminhar','Recepção' );
		$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' => 'Os dados do consulta foram atualizados 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 ( $cf_response, $response_messages );
		

	}
	              
	public function registerRecepcaoSenhaAguardar(): Response {

		$cf_service = new ChameFacilService();
		if(!$cf_service->validrequestRecepcaoAguardar( $_POST )){
			return $this->response->setStatusCode( 400 )
			->setJSON( [
					'message' => 'Dados invalidos, revisar os dados.',
					'data' => [ ]
			] );
		}
		$cf_response = $cf_service->registerRecepcaoSenha( $_POST,'Aguardar','Recepção' );
		$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' => 'Os dados do consulta foram atualizados 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 ( $cf_response, $response_messages );

	}
	
	public function registerRespostaChameFacil(): Response {
		
		$cf_service = new ChameFacilService();
// 		if (!$cf_service->validrequestSenhaChamar( $_POST )) {
// 			return $this->response->setStatusCode( 400 )
// 			->setJSON( [
// 					'message' => 'Dados invalidos, revisar os dados.',
// 					'data' => [ ]
// 			] );
// 		}
		$cf_response = $cf_service->registerRespostaChameFacil( $_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' => 'Os dados dA consulta foram gravados 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.'
				],
				ServiceResponseInterface::UNKNOWN_ERROR => [
						'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
						'message' => 'Erro interno do servidor.'
				]
		];
		return $this->getResponse ( $cf_response, $response_messages );
		
		
	}

	public function getRecepcaoSenha(int $id_senha, int $id_pet, int $id_unidade): Response {
		$cf_service = new ChameFacilService();
		$cf_response = $cf_service->getRecepcaoSenha( $id_senha, $id_pet, $id_unidade);
		$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' => 'Os dados do consulta foram atualizados 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 ( $cf_response, $response_messages );

	}

	public function getMedicoSenha(int $id_senha, int $id_pet, int $id_unidade, int $id_filainterna): Response {
		$cf_service = new ChameFacilService();
		$cf_response = $cf_service->getMedicoSenha( $id_senha, $id_pet, $id_unidade, $id_filainterna);
		$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' => 'Os dados do consulta foram atualizados 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 ( $cf_response, $response_messages );
		

	}

}

