"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clearWishlist = exports.getWishlistCount = exports.removeFromWishlist = exports.toggleWishlistItem = exports.getWishlist = void 0;
const wishlist_service_1 = require("../services/wishlist.service");
const response_utils_1 = require("../utils/response.utils");
// 1. Get User's Complete Wishlist
const getWishlist = async (req, res) => {
    try {
        const userId = req.user?.userId;
        if (!userId)
            return (0, response_utils_1.sendError)(res, 'Unauthorized - Login required', null, 401);
        const wishlistData = await wishlist_service_1.WishlistService.getUserWishlist(userId);
        return (0, response_utils_1.sendSuccess)(res, 'Wishlist retrieved successfully', wishlistData);
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to retrieve wishlist', error.message, 500);
    }
};
exports.getWishlist = getWishlist;
// 2. Toggle Book in Wishlist (Add/Remove)
const toggleWishlistItem = async (req, res) => {
    try {
        const userId = req.user?.userId;
        const { bookId } = req.body;
        if (!userId)
            return (0, response_utils_1.sendError)(res, 'Unauthorized - Login required to save wishlist items', null, 401);
        if (!bookId)
            return (0, response_utils_1.sendError)(res, 'Book ID is required', null, 400);
        const result = await wishlist_service_1.WishlistService.toggleWishlistItem(userId, bookId);
        return (0, response_utils_1.sendSuccess)(res, result.message, result);
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to update wishlist item', error.message, 500);
    }
};
exports.toggleWishlistItem = toggleWishlistItem;
// 3. Remove Item from Wishlist
const removeFromWishlist = async (req, res) => {
    try {
        const userId = req.user?.userId;
        const bookId = req.params.bookId || req.body.bookId;
        if (!userId)
            return (0, response_utils_1.sendError)(res, 'Unauthorized', null, 401);
        if (!bookId)
            return (0, response_utils_1.sendError)(res, 'Book ID parameter is required', null, 400);
        const result = await wishlist_service_1.WishlistService.removeWishlistItem(userId, bookId);
        return (0, response_utils_1.sendSuccess)(res, result.message, result);
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to remove wishlist item', error.message, 500);
    }
};
exports.removeFromWishlist = removeFromWishlist;
// 4. Get Wishlist Total Count
const getWishlistCount = async (req, res) => {
    try {
        const userId = req.user?.userId;
        if (!userId)
            return (0, response_utils_1.sendSuccess)(res, 'Wishlist count', { count: 0 });
        const count = await wishlist_service_1.WishlistService.getWishlistCount(userId);
        return (0, response_utils_1.sendSuccess)(res, 'Wishlist count retrieved', { count });
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to get wishlist count', error.message, 500);
    }
};
exports.getWishlistCount = getWishlistCount;
// 5. Clear All Items from Wishlist
const clearWishlist = async (req, res) => {
    try {
        const userId = req.user?.userId;
        if (!userId)
            return (0, response_utils_1.sendError)(res, 'Unauthorized', null, 401);
        const result = await wishlist_service_1.WishlistService.clearWishlist(userId);
        return (0, response_utils_1.sendSuccess)(res, result.message, result);
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to clear wishlist', error.message, 500);
    }
};
exports.clearWishlist = clearWishlist;
//# sourceMappingURL=wishlist.controller.js.map