<?php

namespace Modules\Fournisseur\Repository;

use Helpers\QueryBuilder\AbsRepository;

class Evaluation extends AbsRepository
{

    
    /**
     * AllEvaluation
     * @param string $code
     * @return array<mixed>
     */
     // phpcs:ignore
    public function AllEvaluation(string $code) : ?array
    {
        $req = "SELECT a.ID_CAMP ID_CAMP, c.LIBELLE LIBELLE, a.NOTE NOTE, a.CODE_FOU 
                FROM CAMP_LST_FOUR a with (nolock)
                LEFT JOIN CAMP_ENT c with (nolock) on c.ID_CAMP = a.ID_CAMP
                WHERE a.CODE_FOU=:value";
        
        $arrayReq = [':value' => $code];
        
        return $this->fetchAssocAll($req, $arrayReq);
    }
    
    /**
     * ListeNoteurs
     * @param string $code
     * @param string $campagne
     * @return array<mixed>
     */
    // phpcs:ignore
    public function ListeNoteurs(string $code, string $campagne) : ?array
    {
        $code = addslashes($code);
        $campagne = addslashes($campagne);// TODO
        
        $req = "SELECT liste.NOTEUR Noteur, h.NOM, liste.ID_CAMP ID_CHAMP, noteur.CODE_FOU, u.NOM_NOTEUR, liste.NOTEUR_EXTERNE 
                from (select * from CAMP_LST_NOT_FOUR a with(nolock) WHERE CODE_FOU='$code' and a.ID_CAMP='$campagne') noteur
                FULL JOIN (select * from CAMP_LST_NOT_CAMP a with(nolock) WHERE a.ID_CAMP = '$campagne')  liste ON liste.NOTEUR = noteur.NOTEUR
                LEFT JOIN CAMP_ENT c with(nolock) on c.ID_CAMP = liste.ID_CAMP
                LEFT JOIN HASTUTIL h with(nolock) on h.CODE = liste.NOTEUR
                left join CAMP_NOTEX u with(nolock) on u.ID_NOTEUR = liste.NOTEUR";
        
        $liste = $this->pdo->prepare($req);

        $liste->execute();
        return $liste->fetchAll($this->pdo::FETCH_ASSOC);
    }
    
    
    /**
     * listeThemePere
     * @param string $idCampagne
     * @return array<mixed>
     */
    public function listeThemePere(string $idCampagne) : ?array
    {
        $req = "select * from CAMP_QST_TH with (nolock) where ID_CAMP=:id and RTRIM(LTRIM(ID_PERE))= ''";
        
        $arrayReq = [':id' => $idCampagne];
        
        return $this->fetchAssocAll($req, $arrayReq);
    }
    
    /**
     * listeThemeFils
     * @param string $idCampagne
     * @param string $idPere
     * @return array<mixed>
     */
    public function listeThemeFils(string $idCampagne, string $idPere) : ?array
    {
        $req = "select * from CAMP_QST_TH with (nolock) where ID_CAMP=:id and ID_PERE=:idpere";
        
        $arrayReq = [':id' => $idCampagne, ':idpere' => $idPere];
        
        return $this->fetchAssocAll($req, $arrayReq);
    }
    
    /**
     * listeQuestion
     * @param string $idCampagne
     * @param string $idTheme
     * @return array<mixed>
     */
    public function listeQuestion(string $idCampagne, string $idTheme) : ?array
    {
        $req = "select * from CAMP_QST_Q with (nolock) where ID_CAMP=:id and ID_THEME=:idTheme";
        
        $arrayReq = [':id' => $idCampagne, ':idTheme' => $idTheme];
        
        return $this->fetchAssocAll($req, $arrayReq);
    }
}
