<?php

namespace Gateway;
use PDO;

class FavoriteGateway extends Gateway
{

    public function createFavoriteGateway(int $idUser, int $idQuote) : bool
    {
        $query = "
            INSERT INTO Favorite
            VALUES (:user, :quote)
        ";

        return $this -> co -> executeQuery($query, [
            'user' => array($idUser, PDO::PARAM_INT),
            'quote' => array($idQuote, PDO::PARAM_INT)
        ]);
    }

    public function findFavoriteById(int $idUser, int $idQuote) : array
    {
        $query = "
            SELECT * FROM Favorite
            WHERE user_f = :user AND quote_f = :quote
        ";

        $this -> co -> executeQuery($query, [
            'user' => array($idUser, PDO::PARAM_INT),
            'quote' => array($idQuote, PDO::PARAM_INT)
        ]);

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

    public function findFavoriteByUser(int $idUser) : array
    {
        $query = "
            SELECT * FROM Favorite
            WHERE user_f = :user
        ";

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

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

    public function findAllFavorite() : array
    {
        $query = "SELECT * FROM Favorite";

        $this -> co -> executeQuery($query);

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

    public function deleteFavoriteGateway(int $idUser, int $idQuote) : bool
    {
        $query = "
            DELETE FROM Favorite
            WHERE user_f = :user AND quote_f = :quote
        ";

        return $this -> co -> executeQuery($query, [
            'user' => array($idUser, PDO::PARAM_INT),
            'quote' => array($idQuote, PDO::PARAM_INT)
        ]);
    }

}