const { Wishlist, Book, sequelize } = require('./models');

async function testWishlist() {
    try {
        await sequelize.authenticate();
        console.log("DB Connected.");

        // Use an existing user_id or a dummy 0. The error is likely structure, not empty data.
        const userId = 1;

        console.log("Attempting to fetch wishlist with full attributes...");
        const wishlist = await Wishlist.findAll({
            where: { user_id: userId },
            include: [{
                model: Book,
                attributes: ['id', 'title', 'price', 'originalPrice', 'image', 'author', 'rating', 'stock']
            }],
            order: [['created_at', 'DESC']]
        });

        console.log("Wishlist fetch success:", JSON.stringify(wishlist, null, 2));
    } catch (error) {
        console.error("Wishlist fetch failed:", error);
    } finally {
        await sequelize.close();
    }
}

testWishlist();
