<?php

namespace Modules\GlobalApplication\Repository;

class ImportQuestion
{
    
    private $pdo;
    
    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }
    
    /**
     * listeModelByGrillModel
     * @param string $idModel
     * @return array<mixed>
     */
    public function listeModelByGrillModel(string $idModel) : ?array
    {
        $req = "SELECT * FROM GRIL_MOD_ENT with (nolock) where ID_GRILLE = :idModel";
        
        $arrayReq = [
            ':idModel' => $idModel,
        ];
        


        $model = $this->pdo->prepare($req);
        $model->execute($arrayReq);
        return $model->fetchAll($this->pdo::FETCH_ASSOC);
    }
    // Cette fonction va nous lister les themes en fonction d'un model passé en parametre
    /**
     * This function will list all the thems by a model function which takes parameter
     * @param string $idModel
     * @return array<mixed>
     */
    public function listeThemeByModel(string $idModel) : ?array
    {
        $req = "SELECT * FROM GRIL_THEME with (nolock) where ID_MODEL = :idModel";
        
        $arrayReq = [
            ':idModel' => $idModel,
        ];
        


        $theme = $this->pdo->prepare($req);
        $theme->execute($arrayReq);
        return $theme->fetchAll($this->pdo::FETCH_ASSOC);
    }
    /**
     * listeThemeCampagne
     * @return array<mixed>
     */
    public function listeThemeCampagne() : ?array
    {
        $req = "SELECT * FROM CAMP_QST_TH with (nolock)";

        $theme = $this->pdo->prepare($req);
        $theme->execute([]);
        return $theme->fetchAll($this->pdo::FETCH_ASSOC);
    }
    // Cette fonction va nous permettre
    /**
     * listeQuestion
     * @param string $idTheme
     * @return array<mixed>
     */
    public function listeQuestion(string $idTheme = null) : ?array
    {
        if ($idTheme != null) {
            $req = "SELECT * FROM GRIL_QST_Q with (nolock) where ID_THEME = :idTheme";
            
            $arrayReq = [
                ':idTheme' => $idTheme,
            ];

    
            $question = $this->pdo->prepare($req);
            $question->execute($arrayReq);
            return $question->fetchAll($this->pdo::FETCH_ASSOC);
        }
        if ($idTheme == null) {
            $req = "SELECT * FROM GRIL_QST_Q with (nolock)";
    
            $question = $this->pdo->prepare($req);
            $question->execute([]);
            return $question->fetchAll($this->pdo::FETCH_ASSOC);
        } else {
            return array();
        }
    }

    /**
     * detailLoupe
     * @param string $idQuest
     * @return array<string>
     */
    public function detailLoupe(string $idQuest) : ?array
    {
        $req = "SELECT * FROM GRIL_QST_Q with (nolock) where ID_QUEST = :idQuestion";
    
        $question = $this->pdo->prepare($req);
        $question->execute([':idQuestion' => $idQuest]);

        return $question->fetch($this->pdo::FETCH_ASSOC);
    }
}
