const favoriteFunction = require("../functions/favourite");

const addToFavorite = async (req, res) => {
    try {
        const favorite = await favoriteFunction.addToFavourites(req);
        if(!favorite){
            return res.status(200).json({
                success: true,
                msg: "Removed From Favorites!"
            });
        } else {
            return res.status(200).json({
                success: true,
                msg: "Added to Favorites!"
            })
        }
    } catch (error) {
        console.log("Having Errors :", error);
        return res.status(403).json({
            success: false,
            msg: "Something Went Wrong!",
            error: error.message
        })        
    }
};

const getAllFavorites = async (req, res) => {
    try {
        const favorites = await favoriteFunction.getAllFavourites(req);
        if(favorites.length === 0){
            return res.status(200).json({
                success: false,
                msg: "No Favorites Found!"
            })
        } else {
            return res.status(200).json({
                success: true,
                msg: "All Favorites!",
                data: favorites
            })            
        }
    } catch (error) {
        console.log("Having Errors :", error);
        return res.status(403).json({
            success: false,
            msg: "Something Went Wrong!",
            error: error.message
        })        
    }    
};

module.exports = {
    addToFavorite,
    getAllFavorites
};