<?php

namespace Gateway;
use Gateway\Connection;
use PDO;


class QuizGateway
{
    private Connection $co;

    public function __construct(Connection $co)
    {
        $this -> co = $co;
    }

    public function create(int $id_quiz, int $nb_questions) : bool
    {
        $query = "
            INSERT INTO Quiz
            VALUES (:id_q, :nb_q)
        ";

        return $this -> co -> executeQuery($query, [
            ':id_q' => array($id_quiz, PDO::PARAM_INT),
            ':nb_q' => array($nb_questions, PDO::PARAM_INT)
        ]);
    }

    public function findQuizById(int $id) : array
    {
        $query = "SELECT * FROM Quiz WHERE id_quiz = :id_q";
        $this -> co -> executeQuery($query, [':id_q' => array($id, PDO::PARAM_INT)]);
        return $this -> co -> getResults();
    }

    public function delete(int $id) : bool
    {
        $query = "DELETE FROM Quiz WHERE id_quiz = :id_q";
        return $this -> co -> executeQuery($query, [':id_q' => array($id, PDO::PARAM_INT)]);
    }

    public function findAll() : array
    {
        $query = "SELECT * FROM Quiz";
        $this -> co -> executeQuery($query);
        return $this -> co -> getResults();
    }

}