<?php

namespace Gateway;
use PDO;

class QuizQuestionGateway extends Gateway
{

    public function createQuizQuestionGateway(int $idQuiz, int $idQuestion): bool
    {
        $query = "
            INSERT INTO Quiz_Question
            VALUES (:id_quiz, :id_question)
        ";

        return $this -> co -> executeQuery($query, [
            'id_quiz' => array($idQuiz, PDO::PARAM_INT),
            'id_question' => array($idQuestion, PDO::PARAM_INT)
        ]);
    }

    public function findQuizQuestionById(int $idQuiz, int $idQuestion) : array
    {
        $query = "
            SELECT * FROM Quiz_Question
            WHERE quiz = :id_quiz AND question_qq = :id_question
        ";

        $this -> co -> executeQuery($query, [
            'id_quiz' => array($idQuiz, PDO::PARAM_INT),
            'id_question' => array($idQuestion, PDO::PARAM_INT)
        ]);

        return $this -> co -> getResults();
    }

    public function findQuestionsFromQuiz(int $idQuiz) : array
    {
        $query = "
            SELECT * FROM Quiz_Question
            WHERE quiz = :id_quiz
        ";

        $this -> co -> executeQuery($query, ['id_quiz' => array($idQuiz, PDO::PARAM_INT)]);

        return $this -> co -> getResults();
    }

    public function deleteQuizQuestionGateway(int $idQuiz, int $idQuestion) : bool
    {
        $query = "
            DELETE FROM Quiz_Question
            WHERE quiz = :id_quiz AND question_qq = :id_question
        ";

        return $this -> co -> executeQuery($query, [
            'id_quiz' => array($idQuiz, PDO::PARAM_INT),
            'id_question' => array($idQuestion, PDO::PARAM_INT)
        ]);
    }

    # To do :
    # Method that deletes all questions related to a quiz



}