<?php
namespace Modules\API\APIInterne\OxaMobility\Controller;

use GuzzleHttp\Psr7\Response;
use Helpers\Outil\Sql;
use Modules\Index\Repository\Connexion;

class APPController extends AbsApiController
{
    public function INITAction() :Response
    {
        $version = new \Entity\Model\Version($this->pdo);
        $version = $version->find(['CLE' => 1]);
        
        $paravrac = new \Entity\Model\Paravrac($this->pdo);
        $indVers = $paravrac->find(['TYPEPARV' => 'PARAMGEN' , 'CODEPARV' => 'RELMIN']);
        $afficherRayon = $paravrac->find(['TYPEPARV' => 'OXAPROC' , 'CODEPARV' => 'AFFRAYON']);
        $codeLangueBDD = $paravrac->find(['TYPEPARV' => 'PARAMOXA', 'CODEPARV' => 'LNGBDD']);
        $codeUniteDEF = $paravrac->find(['TYPEPARV' => 'PARAMGEN', 'CODEPARV' => 'UNITE_DEF']);
        // $logoEnteteGauche = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'LOGO_ENTETE_GAUCHE']);
        // $logoEnteteDroit = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'LOGO_ENTETE_DROITE']);
        // $logoEnteteMobile = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'LOGO_ENTETE_MOBILE']);
        // $logoEntetePied = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'LOGO_ENTETE_PIED']);
        // $logoLogin = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'LOGO_LOGIN']);

        /**
         *
         * rajout de la fonct commande Comptoir
         */
        
        $cdeComptoirActif = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'CDE_COMPTOIR_PAR_MONTANT_ACTIVE']);
        $articleCdeComptoir = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'CDE_COMPTOIR_PAR_MONTANT_CODE_ART']);

        $cdeComptoirParArticleMasquee = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'CDE_COMPTOIR_PAR_ARTICLE_MASQUE']);
        
        $paramOxa = new \Entity\Model\ParamOxa($this->pdo);
        $NumClt = $paramOxa->find(['CLE' => 1]);
        
        
        $trad = $this->getTranslationService();
        
        
        $return['NumVers']= sprintf('%.2f', $version['NUM_VERS']);
        $return['IndVers']=$indVers['LIB01PARV']?? '';
        $return['NumClt']=$NumClt['NO_SITCL']?? '';
        $return['NomSiteClt']=$NumClt['NOM_SITE']?? '';
        /** @phpstan-ignore-next-line */
        $return['DateVers']= $this->getDateVersion();
        $return['ParamsEnv']['AfficheRayonOouN']=$afficherRayon['LIB01PARV']??'' ;
        $return['ParamsEnv']['CodeLangueBDD']=$codeLangueBDD['LIB01PARV']??'';
        $return['ParamsEnv']['CodeDeviseBDD']=Sql::parametr($this->pdo, 'HADEVSTK');
        $return['ParamsEnv']['CodeUniteDEF']=$codeUniteDEF['LIB01PARV']??'';
        $return['ParamsMproc']['CdeComptoirParMnt'] = ($cdeComptoirActif['LIB01PARV']=='O' && $articleCdeComptoir)? 'true':'false';
        $return['ParamsMproc']['CdeComptoirParArt'] = ($cdeComptoirParArticleMasquee['LIB01PARV']=='O')? 'false':'true';
        // $return['ParamsMproc']['URL_logo_entete_gauche']=$logoEnteteGauche['LIB01PARV']??'';
        // $return['ParamsMproc']['URL_logo_entete_droite']=$logoEnteteDroit['LIB01PARV']??'';
        // $return['ParamsMproc']['URL_logo_entete_mobile']=$logoEnteteMobile['LIB01PARV']??'';
        // $return['ParamsMproc']['URL_logo_pied']=$logoEntetePied['LIB01PARV']??'';
        // $return['ParamsMproc']['URL_logo_login']=$logoLogin['LIB01PARV']??'';
        $return['Trads']['MLS_NomProduitTitrePage'] = $trad->t('OXA.MPROC');
        $return['Trads']['MLS_Menu_Commandes'] = $trad->t('Commandes');
        $return['Trads']['MLS_Menu_Fournisseurs'] = $trad->t('Fournisseurs');
        $return['Trads']['MLS_Articles'] = $trad->t('Articles');
        $return['Trads']['MLS_TexteChampsObligatoires'] = $trad->t('Champs obligatoires');
        $return['Trads']['MLS_TexteBoutonRetour'] = $trad->t('Retour');
        $return['Trads']['MLS_Panier_Texte_Article'] = $trad->t('Articles') . $trad->colon();
        $return['Trads']['MLS_Panier_Texte_Fournisseur'] = $trad->t('Fournisseur :');
        $return['Trads']['MLS_Panier_Texte_Total'] = $trad->t('Total (HT) :');
        $return['Trads']['MLS_Panier_Texte_HT'] = $trad->t('HT');
        $return['Trads']['MLS_Valider'] = $trad->t('Valider');
        $return['Trads']['MLS_Fermer'] = $trad->t('Fermer');
        $return['Trads']['MLS_Annuler'] = $trad->t('Annuler');
        $return['Trads']['MLS_Retour'] = $trad->t('Retour');
        $return['Trads']['MLS_Supprimer'] = $trad->t('Supprimer');
        $return['Trads']['MLS_Patienter'] = $trad->t('Veuillez patienter...');
        $return['Trads']['MLS_MessageErreur'] = $trad->t('Une erreur est survenue. Veuillez recommencer, ou contactez votre administrateur.');
        $return['Trads']['MLS_Filtrer'] = $trad->t('Filtrer');
        $return['Trads']['MLS_AucunResultat'] = $trad->t('Aucun résultat');
        $return['Trads']['MLS_SaisieIncorrect'] = $trad->t('Saisie incorrecte');
        $return['Trads']['MLS_Menu_Signature'] = $trad->t('Signature');
        $return['Trads']['MLS_Menu_MonCompte'] = $trad->t('Mon compte');
        $return['Trads']['MLS_Menu_Accueil'] = $trad->t('Accueil');
        $return['Trads']['MLS_Menu_Deconnexion'] = $trad->t('Déconnexion');
        $return['Trads']['MLS_Menu_Reception'] = $trad->t('Réceptionner');
        $return['Trads']['MLS_Menu_Signature'] = $trad->t('Mes documents à signer');
        $return['Trads']['MLS_Titre_Reception'  ] = $trad->t('Réception');
        $return['Trads']['MLS_Titre_Signature'  ] = $trad->t('Signature');
        $return['Trads']['MLS_Cde_Comptoir_Erreur'] = $trad->t('Attention votre panier en cours sera supprimé pour créer la nouvelle commande comptoir.');
        $return['Trads']['MLS_Continuer']                          = $trad->t('Voulez-vous continuer ?');
        $return['Trads']['MLS_TailleMaxFic'] = $trad->t('La taille de votre fichier %1 (%2 Mo) est trop grande (max %3 Mo).');
        $return['Trads']['MLS_Deconnecte '] = $trad->t('Vous avez été déconnecté.');
        
        return $this->createApiResponse($return);
    }
    
    // phpcs:ignore
    public function INIT_1Action() :Response
    {
    
        $version = new \Entity\Model\Version($this->pdo);
        $version = $version->find(['CLE' => 1]);
    
        $paravrac = new \Entity\Model\Paravrac($this->pdo);
        $indVers = $paravrac->find(['TYPEPARV' => 'PARAMGEN' , 'CODEPARV' => 'RELMIN']);
        $afficherRayon = $paravrac->find(['TYPEPARV' => 'OXAPROC' , 'CODEPARV' => 'AFFRAYON']);
        $codeLangueBDD = $paravrac->find(['TYPEPARV' => 'PARAMOXA', 'CODEPARV' => 'LNGBDD']);
        $codeUniteDEF = $paravrac->find(['TYPEPARV' => 'PARAMGEN', 'CODEPARV' => 'UNITE_DEF']);
        /*$logoEnteteGauche = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'LOGO_ENTETE_GAUCHE']);
        $logoEnteteDroit = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'LOGO_ENTETE_DROITE']);
        $logoEnteteMobile = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'LOGO_ENTETE_MOBILE']);
        $logoEntetePied = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'LOGO_ENTETE_PIED']);
        $logoLogin = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'LOGO_LOGIN']);*/
        $cdeComptoirActif = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'CDE_COMPTOIR_PAR_MONTANT_ACTIVE']);
        $articleCdeComptoir = $paravrac->find(['TYPEPARV' => 'OXAMPROC', 'CODEPARV' => 'CDE_COMPTOIR_PAR_MONTANT_CODE_ART']);
        
        $paramOxa = new \Entity\Model\ParamOxa($this->pdo);
        $NumClt = $paramOxa->find(['CLE' => 1]);
    
        $CodeDeviseBDD = (new \Entity\Model\Parametr($this->pdo))->get();
        
        
        $return['NumVers']=$version['NUM_VERS'] ?? '';
        $return['IndVers']=$indVers['LIB01PARV']?? '';
        $return['NumClt']=$NumClt['NO_SITCL']?? '';
        $return['NomSiteClt']=$NumClt['NOM_SITE']?? '';
        $return['ParamsEnv']['AfficheRayonOouN']=$afficherRayon['LIB01PARV']??'' ;
        $return['ParamsEnv']['CodeLangueBDD']=$codeLangueBDD['LIB01PARV']??'';
        $return['ParamsEnv']['CodeDeviseBDD']=$CodeDeviseBDD->HADEVSTK??'';
        $return['ParamsEnv']['CodeUniteDEF']=$codeUniteDEF['LIB01PARV']??'';
        /*$return['ParamsMproc']['URL_logo_entete_gauche']=$logoEnteteGauche['LIB01PARV']??'';
        $return['ParamsMproc']['URL_logo_entete_droite']=$logoEnteteDroit['LIB01PARV']??'';
        $return['ParamsMproc']['URL_logo_entete_mobile']=$logoEnteteMobile['LIB01PARV']??'';
        $return['ParamsMproc']['URL_logo_pied']=$logoEntetePied['LIB01PARV']??'';
        $return['ParamsMproc']['URL_logo_login']=$logoLogin['LIB01PARV']??'';*/
        $return['ParamsMproc']['CdeComptoirParMnt'] = ($cdeComptoirActif['LIB01PARV']=='O' && $articleCdeComptoir)? 'true':'false';
    
        return $this->createApiResponse($return);
    }
    
    // phpcs:ignore
    public function INIT_2Action() :Response
    {
        $trad = $this->getTranslationService();
        
        $return['Trads']['MLS_NomProduitTitrePage'] = $trad->t('OXA.MPROC');
        $return['Trads']['MLS_Menu_Commandes'] = $trad->t('Commandes');
        $return['Trads']['MLS_Menu_Fournisseurs'] = $trad->t('Fournisseurs');
        $return['Trads']['MLS_Articles'] = $trad->t('Articles');
        $return['Trads']['MLS_TexteChampsObligatoires'] = $trad->t('Champs obligatoires');
        $return['Trads']['MLS_TexteBoutonRetour'] = $trad->t('Retour');
        $return['Trads']['MLS_Panier_Texte_Article'] = $trad->t('Articles') . $trad->colon();
        $return['Trads']['MLS_Panier_Texte_Fournisseur'] = $trad->t('Fournisseur') . $trad->colon();
        $return['Trads']['MLS_Panier_Texte_Total'] = $trad->t('Total (HT) :');
        $return['Trads']['MLS_Panier_Texte_HT'] = $trad->t('HT');
        
        return $this->createApiResponse($return);
    }
}
