<?php
namespace Modules\API\APIExterne\Controller;

use API\Altares\IntuizPartenaire;
use API\Partenaire\Service\PartenaireService;
use Helpers\Outil\Sql;
use Modules\API\APIExterne\MagicRelais\ConsultExportComparatif;
use Modules\API\APIExterne\MagicRelais\ConsultImport;
use Modules\API\APIExterne\MagicRelais\EnvoiConsult;
use Modules\Consultation\Service\EnvoieExcelService;
use Skeleton\Controller\Controller;

class RelaiMagicController extends Controller
{

    public function indexAction() :string
    {
        header("Content-type: text/xml");
        $token = $this->request->getAttribute('token');
        $post = $this->request->getParsedBody();
        
        $paramDico = Sql::paramDicoAllCol($this->pdo, 'MAGIC_HTTP_RELAIS_PHP', $token);

        switch ($paramDico['ID2']) {
            case 'ENVOI_CONSULT':
                return (new EnvoiConsult($this->pdo, $token))->traitement($this->router, $this->base, $this->getTranslationService());
            case 'CONSULT_IMPORT':
                return (new ConsultImport($this->pdo, $token))->traitement($this->base, $this->getTranslationService(), $this->renderer);
            case 'CONSULT_EXPORT_COMP':
                return (new ConsultExportComparatif(
                    $this->renderer,
                    $this->pdo,
                    $this->router,
                    $this->contenaire
                ))->traitement($paramDico);
        
            default:
        }
        return '<?xml version="1.0" encoding="iso-8859-1" standalone="no" ?>
                    <Relais_HTTP_Out>
                    <Statut>E</Statut>
                    <Message>Code API introuvable</Message>
                </Relais_HTTP_Out>';
    }
}
