<?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, 
            comm_fou.COMMENTAIRE_FINAL, comm_fou.PLAN_ACTION, c.DTEFIN
                FROM CAMP_LST_FOUR a with (nolock)
                    LEFT JOIN CAMP_ENT c with (nolock) on c.ID_CAMP = a.ID_CAMP
                LEFT JOIN CAMP_NOT_FIN comm_fou ON comm_fou.ID_CAMP = a.ID_CAMP 
                    AND comm_fou.CODE_FOU = a.CODE_FOU
                    AND comm_fou.ID_THEME = ''
                    AND comm_fou.ID_QUEST = 0
                WHERE a.CODE_FOU=:value
                    AND c.STATUT = 'T'";
        
        $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
    {
        $query = "SELECT noteur.NOTEUR Noteur, h.NOM, noteur.ID_CAMP ID_CHAMP, noteur.CODE_FOU, u.NOM_NOTEUR, noteur.NOTEUR_EXTERNE 
                FROM (
                    SELECT NOTEUR, ID_CAMP, CODE_FOU, NOTEUR_EXTERNE 
                    FROM CAMP_LST_NOT_FOUR a WITH(NOLOCK) 
                    WHERE CODE_FOU = :CODE_FOU AND a.ID_CAMP = :ID_CAMP
                ) noteur
                    LEFT JOIN CAMP_ENT c WITH(NOLOCK) ON c.ID_CAMP = noteur.ID_CAMP
                    LEFT JOIN HASTUTIL h WITH(NOLOCK) ON h.CODE = noteur.NOTEUR
                    LEFT JOIN CAMP_NOTEX u WITH(NOLOCK) ON u.ID_NOTEUR = noteur.NOTEUR";

        $params = [
            ':CODE_FOU' => $code,
            ':ID_CAMP' => $campagne
        ];

        return $this->fetchAssocAll($query, $params);
    }
    
    
    /**
     * 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);
    }
}
