<?php
namespace Modules\Additional\Specifique\Client155;

use Helpers\Parametres\Parametres;
use Modules\Additional\Specifique\Client155\Modules\Consultation\Controller\ConsolidationController;
use Modules\Additional\Specifique\Client155\Modules\Declaratif\Controller\DeclaratifController;
use Modules\Additional\Specifique\Client155\Modules\Fournisseur\Controller\ImportReportingController;
use Modules\Additional\Specifique\Client155\Modules\Fournisseur\Controller\ReportingPerformanceController;
use Psr\Container\ContainerInterface;
use Skeleton\Module;
use Skeleton\Router;
use Skeleton\Renderer\RendererInterface;

class Specifique155Module extends Module
{

    const DEFINITIONS = __DIR__ . '/config.php';

    /**
     * @param ContainerInterface $container
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    public function __construct(ContainerInterface $container)
    {
        $container->get(RendererInterface::class)->addPath('Specifique155.Fournisseur', __DIR__.'/Modules/Fournisseur/view');
        $container->get(RendererInterface::class)->addPath('Specifique155.Consultation', __DIR__.'/Modules/Consultation/view');
        $container->get(RendererInterface::class)->addPath('Specifique155.Declaratif', __DIR__.'/Modules/Declaratif/view');
        $router = $container->get(Router::class);

        $parametres     = new Parametres();
        $fourniss       = $parametres->id_fournisseur;
        $consultation   = $parametres->expression_point_tiret_underscore;
        $alpha_min      = $parametres->expression_point_tiret_underscore;
        $fullyAlphaMin  = $parametres->expression_alpha_min;
        $numeric        = '[0-1]';
        $periode        = '[0-9]';
        $sousFamille    = '[0-9]';

        $baseUrl = $container->get('baseUrl') . $container->get('Specifique155.prefix');

        // INITIALISATION DES ROUTES

        /**
         * ROUTES REPORTING PERFORMANCE - SPEC 4743
         */
        $router->get(
            $baseUrl. '/reporting-performance/{id:'.$fourniss.'+}',
            ReportingPerformanceController::class,
            'Specifique155.reportingPerformance.index',
        );

        $router->get(
            $baseUrl . '/reporting-performance/{id:'.$fourniss.'+}/new-report',
            ReportingPerformanceController::class,
            'Specifique155.reportingPerformance.newReport',
        );

        $router->get(
            $baseUrl . '/reporting-performance/{id:'.$fourniss.'+}/creation-report/{action:' . $alpha_min . '+}[/{periode:'.$periode.'+}/{ssf:'.$sousFamille.'+}]',
            ReportingPerformanceController::class,
            'Specifique155.reportingPerformance.createReport',
        );

        $router->get(
            $baseUrl . '/reporting-performance/{id:'.$fourniss.'+}/ajax/chiff-aff-update',
            ReportingPerformanceController::class,
            'Specifique155.reportingPerformance.chiffAffUpdate',
        );

        $router->get(
            $baseUrl . '/report-performance/edit/{id:'.$fourniss.'+}/{periode:'.$periode.'+}/{ssf:'.$sousFamille.'+}',
            ReportingPerformanceController::class,
            'Specifique155.reportingPerformance.editReport',
        );

        $router->get(
            $baseUrl . '/import/reporting-performance',
            ReportingPerformanceController::class,
            'Specifique155.reportingPerformance.importMultiple',
        );

        $router->get(
            $baseUrl . '/reporting-performance/{id:'.$fourniss.'+}/import',
            ReportingPerformanceController::class,
            'Specifique155.reportingPerformance.import',
        );

        $router->get(
            $baseUrl . '/import/reporting-performance/{type:'.$fullyAlphaMin.'+}',
            ImportReportingController::class,
            'Specifique155.importReporting.import'
        );

        $router->get(
            $baseUrl . '/report-performance/delete/{id:'.$fourniss.'+}/{periode:'.$periode.'+}/{ssf:'.$sousFamille.'+}',
            ReportingPerformanceController::class,
            'Specifique155.reportingPerformance.delete',
        );

        $router->get(
            $baseUrl . '/reporting-performance/downloadExemple/{type:'.$alpha_min.'+}',
            ReportingPerformanceController::class,
            'Specifique155.reportingPerformance.downloadPattern',
        );

        /**
         * ROUTES CONSOLIDATION GRILLE - SPEC 4754
         */
        $router->get(
            $baseUrl.'/consultation/{id:'.$consultation.'+}/consolider[/{force:'.$numeric.'}]',
            ConsolidationController::class,
            'Specifique155.consolidation.consoliderPopup'
        );

        /**
         * ROUTES DECLARATIF CA - SPEC 4742
         */
        $router->get(
            $baseUrl.'/declaratif[/{force:'.$numeric.'}]',
            DeclaratifController::class,
            'Specifique155.declaratif.index'
        );
    }
}
