<?php

namespace App\Controllers;

use App\Controllers\BaseController;
use App\Validations\LojaCompraValidation;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use App\Services\LojaCompraService;
use App\Services\ServiceResponse\ServiceResponseInterface;

class LojaCompraController extends BaseController {
	
	public function registerCompraCartaoPagseguro():Response {
		
		$dados = $this->getDataPost();
		
		$validar = array ();
		$validar = LojaCompraValidation::addCompraPagseguroCartao( $dados );
		if (count( $validar ) > 0) {
			return $this->response->setStatusCode( 400 )
			->setJSON( [
					'message' => 'Informe os dados corretamente.',
					'erros' => $validar
			] );
		}
		
		
		$service = new LojaCompraService();
		
		$response_service = $service->registerCompraCartaoPagseguro($dados);
		
		$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' => 'Compra cadastrada com sucesso.'
				],
				ServiceResponseInterface::VALIDATION_PARAMS_ERROR => [
						'code' => ResponseInterface::HTTP_FAILED_DEPENDENCY,
						'message' => 'Compra não aprovada pela operadora.'
				],
				ServiceResponseInterface::INSUFFICIENT_DATA => [
						'code' => ResponseInterface::HTTP_BAD_REQUEST,
						'message' => 'Informe os dados corretamente.'
				],
				ServiceResponseInterface::HAVE_CONFLICTS => [
						'code' => ResponseInterface::HTTP_CONFLICT,
						'message' => 'Dados informado em conflito.'
				],
				ServiceResponseInterface::UNKNOWN_ERROR => [
						'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
						'message' => 'Erro Interno.'
				]
		];
		return $this->getResponse( $response_service, $response_messages );
		
		
		
	}

    public function registerCompraMedicinaCarinho():Response {

 	
    	$dados = $this->getDataPost();

        $validar = array ();
        $validar = LojaCompraValidation::addCompraMedicinaCarinho( $dados );
        if (count( $validar ) > 0) {
            return $this->response->setStatusCode( 400 )
                ->setJSON( [
                    'message' => 'Informe os dados corretamente.',
                    'erros' => $validar
                ] );
        }


        $service = new LojaCompraService();

        $response_service = $service->registerCompraMedicinaCarinho($dados);

        $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' => 'Compra cadastrada com sucesso.'
            ],
            ServiceResponseInterface::INSUFFICIENT_DATA => [
                'code' => ResponseInterface::HTTP_BAD_REQUEST,
                'message' => 'Informe os dados corretamente.'
            ],
            ServiceResponseInterface::HAVE_CONFLICTS => [
                'code' => ResponseInterface::HTTP_CONFLICT,
                'message' => 'Dados informado em conflito.'
            ],
            ServiceResponseInterface::UNKNOWN_ERROR => [
                'code' => ResponseInterface::HTTP_INTERNAL_SERVER_ERROR,
                'message' => 'Erro Interno.'
            ]
        ];
        return $this->getResponse( $response_service, $response_messages );



    }
	
	public function registerCompraPixPagseguro():Response {
		
	}

}

