<?php
namespace Modules\Index;

use Modules\Index\Controller\CacheClearController;
use Skeleton\Router;
use Skeleton\Module;
use Helpers\Parametres\Parametres;
use Skeleton\Renderer\RendererInterface;
use Psr\Container\ContainerInterface;
use Modules\Index\Controller\IndexController;
use Modules\Index\Controller\PasswordOublieController;
use Modules\Index\Controller\ConnexionController;
use Modules\Index\Controller\CreationCompteController;
use Modules\Index\Controller\DiagsController;
use Modules\Index\Controller\TableauDeBordController;

class IndexModule extends Module
{
    const DEFINITIONS = __DIR__ . '/config.php';

    public function __construct(ContainerInterface $container)
    {
        $container->get(RendererInterface::class)->addPath('index', __DIR__ . '/views');
        $container->get(RendererInterface::class)->addPath('index-error', __DIR__ . '/views/error');
        $container->get(RendererInterface::class)->addPath('ajaxTableauDeBord', __DIR__ . '/views/ajaxTableauDeBord');
        $container->get(RendererInterface::class)->addPath('outil', __DIR__ . '/views/outil');
        $container->get(RendererInterface::class)->addPath('creationCompte', __DIR__ . '/views/creationCompte');
        $container->get(RendererInterface::class)->addPath('magicSaml2', __DIR__ . '/views/saml2/magic');

        $router = $container->get(Router::class);

        $parametres     = new Parametres();
        $global         = $parametres->expression_global;
        $login          = $parametres->expression_tiret_underscore_accent;
        $uuid          = $parametres->expression_tiret_underscore_accent;
        
        $base_url = $container->get('baseUrl') . $container->get('Index.prefix');
        $base_urlOld = $container->get('baseUrl') .'V2/'. $container->get('Index.prefix');

        // Creation Compte
        $router->public($base_url."/creationCompte", CreationCompteController::class, 'Index.CreationCompte.cordonne');
        $router->public($base_url."/creationCompte/ajaxCoordonnees", CreationCompteController::class, 'Index.CreationCompte.ajaxCoordonnees');
        $router->public($base_url."/creationCompte/ajaxAbonnements", CreationCompteController::class, 'Index.CreationCompte.ajaxAbonnements');
        $router->public($base_url."/creationCompte/ajaxPassword", CreationCompteController::class, 'Index.CreationCompte.ajaxPassword');
        
        $router->public($base_url.'/testSMTP', CreationCompteController::class, 'Index.CreationCompte.testeSMTP');
        
        // Index
        $router->public($container->get('baseUrl') . 'index.php', IndexController::class, 'Index.Index.indexReset');
        $router->get($base_url, IndexController::class, 'Index.Index.index');
        $router->get($base_url."/SRMIndex", IndexController::class, 'Index.Index.SRMIndex');
        
        $router->get($base_url."/ajaxTableauDeBord", IndexController::class, 'Index.Index.ajaxTableauDeBord');
        
        $router->public($base_url."/error", IndexController::class, 'Index.Index.error');
        $router->public($base_url."/forbidden", IndexController::class, 'Index.Index.forbidden'); //403
        $router->public($base_url."/error/droit", IndexController::class, 'Index.Index.errorDroit');
        $router->public($base_url."/error/formulaire", IndexController::class, 'Index.Index.erreurFormulaire');
        $router->public($base_url."/error/en-construction", IndexController::class, 'Index.Index.errorConstruct');
        $router->public($base_url."/error/ip-ban", IndexController::class, 'Index.Index.errorConstruct');

        $router->public($base_url."/logout", IndexController::class, 'Index.Index.logout');
        // Securité CSRF
        $router->public($base_url."/error/securecsrf[/{v1:[A-Za-z0-9]+}]", IndexController::class, 'Index.Index.redirectionCSRF');

        // Securité CSP
        $router->public($base_url."/error/secure-csp-rapport", IndexController::class, 'Index.Index.cspRapport');

        $router->get($base_url."/dev/changeModule", IndexController::class, 'Index.Index.changeModule');
        
        $router->public($base_url."/noPdf", IndexController::class, 'Index.Index.noPdf');
        $router->get($base_url."/specifique", IndexController::class, 'Index.Index.specifique');
        
        $router->public($base_url."/changementPassword[/{token:[A-Za-z0-9]+}]", PasswordOublieController::class, 'Index.Password.changementPassword');
        $router->public($base_url."/error/sessionExpire", PasswordOublieController::class, 'Index.Password.sessionExpire');
        $router->public($base_url . '/validator/isPassword', PasswordOublieController::class, 'Index.validator.isPassword');
        
        /* ____bloc connexion____ */
        $router->public($base_url."/mdpOublie", ConnexionController::class, 'Index.Connexion.mdpOublie');
        $router->public($base_url."/error/integrite", ConnexionController::class, 'Index.Index.errorIntegrite');
        
        // tableau de bord
        $router->get($base_url . "/TableauDeBord", TableauDeBordController::class, 'Index.TableauDeBord.index');
        $router->get($base_url . "/TableauDeBord/favoris", TableauDeBordController::class, 'Index.TableauDeBord.favoris');
        
        // Diags
        $router->public($base_url . "/diags/nouveau-mot-de-passe", DiagsController::class, 'Index.Diags.nouveauMotDePasse');
        $router->public($base_url . "/diags/connexion", DiagsController::class, 'Index.Diags.connexion');
        $router->public($base_url . "/diags/perfRequete", DiagsController::class, 'Index.Diags.perfRequete');
        $router->public($container->get('baseUrl') . "diags.php", DiagsController::class, 'Index.Diags.index');
        $router->public($base_url . "/diags/phpinfo", DiagsController::class, 'Index.Diags.phpinfo');
        $router->public($base_url . "/diags/oxaReport", DiagsController::class, 'Index.Diags.oxaReport');
        $router->public($base_url . "/diags/activeTracingRequete", DiagsController::class, 'Index.Diags.activeTracingRequete');
        
        

        // winCache
        $router->public($base_url. "/cacheclear", CacheClearController::class, 'Index.CacheClear.suppressionCache');

        $router->public($base_urlOld. "/cacheclear", CacheClearController::class, 'Index.CacheClearOLD.suppressionCache');

        $router->public($base_url. "/wincache/suppression-cache-user[/{type:[A-Za-z0-9]+}]", CacheClearController::class, 'Index.CacheClear.suppressionCacheUser');
    }
}
