<?php

namespace Model;
use Gateway\FavoriteGateway;
use Entity\FavoriteEntity;
use Gateway\Gateway;

class FavoriteModel extends Model
{
    public function createFavoriteModel(int $idUser, int $idQuote) : bool
    {
        return $this -> gateway -> createFavoriteGateway($idUser, $idQuote);
    }

    public function getFavoriteById(int $idUser, int $idQuote) : ?FavoriteEntity
    {
        $res = $this -> gateway -> findFavoriteById($idUser, $idQuote);

        if ($res)
        {
            return new FavoriteEntity (
                $res[0]['user_f'],
                $res[0]['quote_f'],
            );
        }
        return null;
    }

    public function getFavoriteByUser(int $idUser) : array
    {
        $res = $this -> gateway -> findFavoriteByUser($idUser);

        $favorites = [];

        foreach ($res as $favorite)
        {
            $favorites = new FavoriteEntity (
                $favorite['user_f'],
                $favorite['quote_f']
            );
        }
        return $favorites;
    }

    public function getAllFavorite() : array
    {
        $res = $this -> gateway -> findAllFavorite();

        $favorites = [];

        foreach ($res as $favorite)
        {
            $favorites = new FavoriteEntity (
                $favorite['user_f'],
                $favorite['quote_f']
            );
        }
        return $favorites;
    }

    public function removeFavorite(int $idUser, int $idQuote) : bool
    {
        return $this -> gateway -> deleteFavoriteGateway($idUser, $idQuote);
    }
}