<?php

namespace Modules\Reception;

use Helpers\Parametres\Parametres;
use Modules\Reception\Controller\DocumentController;
use Modules\Reception\Controller\ExportReceptionController;
use Modules\Reception\Controller\ImpressionBonRecepController;
use Modules\Reception\Controller\ImpressionBonSortieController;
use Modules\Reception\Controller\WorkflowController;
use Modules\Reception\Controller\AjaxController;
use Modules\Reception\Controller\ControleQualiteController;
use Modules\Reception\Controller\CreationBRController;
use Modules\Reception\Controller\GestionBRController;
use Modules\Reception\Controller\IncidentController;
use Modules\Reception\Controller\LotController;
use Modules\Reception\Controller\RepartitionDemandeurController;
use Modules\Reception\Controller\ValidatorCreationController;
use Psr\Container\ContainerInterface;
use Skeleton\Module;
use Skeleton\Renderer\RendererInterface;
use Skeleton\Router;

class ReceptionModule extends Module
{

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

    public function __construct(ContainerInterface $container)
    {
        $container->get(RendererInterface::class)->addPath('Reception', __DIR__ . '/views');

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

        $parametres   = new Parametres();
        $br           = $parametres->id_commande;
        $tab          = $parametres->id_commande;
        $init         = $parametres->id_commande;
        $order        = $parametres->id_commande;
        $type         = $parametres->expression_global;
        $global       = $parametres->expression_global;
        $po           = $parametres->id_commande;
        $MODULE       = $parametres->MODULE;
        $id_document  = '[A-zÀ-ú0-9%._ -$]';

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


        /** ****************** **/
        /** Gestion **/
        $router->get($basePath . "/index[/{type:{$type}+}]", GestionBRController::class, 'Reception.GestionBR.index');
        $router->get($basePath . "/ajax/detailEntetCommande/{order:$order+}", AjaxController::class, 'Reception.Ajax.getCommandeDetailEntet');
        $router->get($basePath . "/ajax/detailArticleCommande/{order:$order+}/{po:$po+}", AjaxController::class, 'Reception.Ajax.getLigneCommandeDetail');
        $router->get($basePath . "/ajax/detailBRLigne/{br:$br+}", AjaxController::class, 'Reception.Ajax.getBRDetail');
        $router->get($basePath . "/ajax/detailBrAnnule/{br:$br+}", GestionBRController::class, 'Reception.GestionBR.viewPreviousReturnVouchers');

        /** ****************** **/
        /** Création BR **/
        $router->get($basePath . "/createdit/{order:$order+}/{type:$type+}/{mode:$type+}/{init:$init+}[/{tab:$tab+}[/{idDoc:$br+}]]", CreationBRController::class, 'Reception.CreationBR.creatEdit');
        $router->get($basePath . "/ajaxUpdateHeading/{type:$type+}[/{id:$br+}]", CreationBRController::class, 'Reception.CreationBR.ajaxUpdateHeading');
        $router->get($basePath . "/ajaxUpdateLine/{order:$order+}/{type:$type+}/{mode:$type+}[/{id:$br+}]", CreationBRController::class, 'Reception.CreationBR.ajaxUpdateLine');
        $router->get($basePath . "/ajaxUpdateCC", CreationBRController::class, 'Reception.CreationBR.ajaxUpdateCC');
        $router->get($basePath . "/ajaxCommentaire/{order:$order+}/{type:$type+}/{mode:$type+}/{line:$order+}", CreationBRController::class, 'Reception.CreationBR.ajaxCommentaire');
        $router->get($basePath . "/saveComment/{order:$order+}/{type:$type+}/{mode:$type+}/{line:$order+}", CreationBRController::class, 'Reception.CreationBR.saveComment');
        $router->get($basePath . "/ajaxUpdateSession[/{id:$br+}]", CreationBRController::class, 'Reception.CreationBR.ajaxUpdateSession');
        $router->get($basePath . "/validate/{type:$type+}/{mode:$type+}[/{confirm:$br+}]", CreationBRController::class, 'Reception.CreationBR.validate');

        /** Gestion documents **/
        $router->get($basePath . "/ajaxDeleteDoc/{ordre:$init+}", CreationBRController::class, 'Reception.CreationBR.ajaxDeleteDoc');

        /** Gestion BR **/
        $router->get($basePath . "/reception/valDevalSupp/{br:$br+}/{action:$type+}", GestionBRController::class, 'Reception.GestionBR.valDevalSupp');

        /** List BR **/
        $router->get($basePath . '/bonrecep/list', GestionBRController::class, 'Reception.GestionBR.list'); // TOOD: not used ?

        $router->get($basePath . "/bonrecep/popup_export[/{origin:$type+}]", ExportReceptionController::class, 'Reception.Export.popupExport');
        $router->get($basePath . "/bonrecep/export[/{origin:$type+}]", ExportReceptionController::class, 'Reception.Export.export');

        /** ****************** **/
        /** Répartition lots **/
        $router->get($basePath . "/lot/listeLots", LotController::class, 'Reception.Lot.listeLots');
        $router->get($basePath . "/lot/ajaxAddBatch/{line:$order+}", LotController::class, 'Reception.Lot.ajaxAddBatch');
        $router->get($basePath . "/lot/ajaxUpdateBatch", LotController::class, 'Reception.Lot.ajaxUpdateBatch');
        $router->get($basePath . "/lot/ajaxRemoveBatch/{line:$order+}[/{batch:$type+}]", LotController::class, 'Reception.Lot.ajaxRemoveBatch');
        $router->get($basePath . "/lot/ajaxUpdateBatchReturn", LotController::class, 'Reception.Lot.ajaxUpdateBatchReturn');

        /** ****************** **/
        /** Validator Création BR **/
        $router->get($basePath . "/validator/saisie", ValidatorCreationController::class, 'Reception.ValidatorCreation.saisie');
        $router->get($basePath . "/validator/batch", ValidatorCreationController::class, 'Reception.ValidatorCreation.batch');

        /** Gestion documents **/

        $router->get($basePath . "/saveDoc/{id:$order+}[/{idDoc:$br+}]", CreationBRController::class, 'Reception.CreationBR.saveDoc');
        $router->get($basePath . "/ajaxDownloadDoc/{id:$order+}/{ordre:$init+}", CreationBRController::class, 'Reception.CreationBR.ajaxDownloadDoc');
        $router->get($basePath . "/document/saveNewDoc/{NO_DA:$MODULE+}/{id:$id_document+}", DocumentController::class, 'Reception.Document.saveNewDoc');
        $router->get($basePath . "/document/saveEditDoc/{NO_DA:$MODULE+}/{id:$id_document+}", DocumentController::class, 'Reception.Document.saveEditDoc');

        /** Gestion incidents **/
        $router->get($basePath . "/saveIncident/{id:$order+}/{type:$type+}/{mode:$type+}", IncidentController::class, 'Reception.Incident.saveIncident');
        $router->get($basePath . "/ajaxDeleteIncident", IncidentController::class, 'Reception.Incident.ajaxDeleteIncident');
        $router->get($basePath . "/ajaxUpdateLineIncident/{order:$order+}/{type:$type+}/{mode:$type+}", IncidentController::class, 'Reception.Incident.ajaxUpdateLineIncident');

        /** Menu intermediaire **/
        $router->get($basePath . "/ajax/detailEntete/{idBR:{$br}+}", GestionBRController::class, 'Reception.GestionBR.ajaxDetailEntete');

        // Impression
        $router->get($basePath . '/{id:' . $br . '+}/impression/{mode:' . $type . '+}', ImpressionBonRecepController::class, 'Reception.Impression.impression');
        $router->get($basePath . '/bon-sortie/{id:' . $br . '+}/impression/{mode:' . $type . '+}', ImpressionBonSortieController::class, 'Reception.ImpressionBonSortie.impression');

        // Workflow
        $router->get($basePath . '/{bonRecepId:' . $br . '+}/workflow', WorkflowController::class, 'Reception.Workflow.summary');
        $router->get($basePath . '/{bonRecepId:' . $br . '+}/workflow/{workflowId:' . $global . '+}', WorkflowController::class, 'Reception.Workflow.detail');

        $router->get($basePath . '/RepartitionDemandeur[/{idDoc:' . $br . '+}]', RepartitionDemandeurController::class, 'Reception.RepartitionDemandeur.listeDemandeur');

        $router->get($basePath . '/ControleQualite/index', ControleQualiteController::class, 'Reception.ControleQualite.liste');
        $router->get($basePath . '/ControleQualite/detail/{idDoc:' . $br . '+}[/{typeCtrl:' . $global . '+}]', ControleQualiteController::class, 'Reception.ControleQualite.ajaxDetailControle');
        $router->get($basePath . '/ControleQualite/saisieControleQualite/{idDoc:' . $br . '+}', ControleQualiteController::class, 'Reception.ControleQualite.saisieControleQualite');
        $router->get($basePath . '/ControleQualite/validate/{idDoc:' . $br . '+}', ControleQualiteController::class, 'Reception.ControleQualite.validate');
    }
}
