<?php

namespace Modules\Reception;

use Helpers\Parametres\Parametres;
use Modules\Reception\Controller\ImpressionBonRecepController;
use Modules\Reception\Controller\ImpressionBonSortieController;
use Modules\Reception\Controller\WorkflowController;
use Modules\Reception\Controller\AjaxController;
use Modules\Reception\Controller\ControleQuanliteController;
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 Modules\Reception\Repository\ControleQualite;
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;

        $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 . "/ajaxUpdateSession[/{id:$br+}]", CreationBRController::class, 'Reception.CreationBR.ajaxUpdateSession');
        $router->get($basePath . "/validate/{type:$type+}/{mode:$type+}[/{confirm:$br+}]", CreationBRController::class, 'Reception.CreationBR.validate');
        $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');


        /** 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+}]", GestionBRController::class, 'Reception.GestionBR.popupExport');
        $router->get($basePath . "/bonrecep/export[/{origin:$type+}]", GestionBRController::class, 'Reception.GestionBR.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');

        /** 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', ControleQuanliteController::class, 'Reception.ControleQuanlite.liste');
        $router->get($basePath . '/ControleQualite/detail/{idDoc:'.$br.'+}[/{typeCtrl:'.$global.'+}]', ControleQuanliteController::class, 'Reception.ControleQuanlite.ajaxDetailControle');
        $router->get($basePath . '/ControleQualite/saisieControleQualite/{idDoc:'.$br.'+}', ControleQuanliteController::class, 'Reception.ControleQuanlite.saisieControleQualite');
        $router->get($basePath . '/ControleQualite/validate/{idDoc:'.$br.'+}', ControleQuanliteController::class, 'Reception.ControleQuanlite.validate');
    }
}
