"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCampaigns = exports.getCrossSells = exports.getUpsells = exports.getFlashDeals = exports.getTierDiscounts = exports.getBundles = exports.getFrequentlyBoughtTogether = void 0;
const smart_sales_service_1 = require("../services/smart-sales.service");
const response_utils_1 = require("../utils/response.utils");
// 1. Frequently Bought Together
const getFrequentlyBoughtTogether = async (req, res) => {
    try {
        const bookId = req.params.bookId;
        if (!bookId)
            return (0, response_utils_1.sendError)(res, 'Book ID is required', null, 400);
        const fbt = await smart_sales_service_1.SmartSalesService.getFrequentlyBoughtTogether(bookId);
        return (0, response_utils_1.sendSuccess)(res, 'Frequently bought together combo retrieved', fbt);
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to get frequently bought together items', error.message, 500);
    }
};
exports.getFrequentlyBoughtTogether = getFrequentlyBoughtTogether;
// 2. Bundles & Combos List
const getBundles = async (req, res) => {
    try {
        const isCombo = req.query.isCombo === 'true' ? true : req.query.isCombo === 'false' ? false : undefined;
        const bundles = await smart_sales_service_1.SmartSalesService.getBundlesAndCombos(isCombo);
        return (0, response_utils_1.sendSuccess)(res, 'Bundles retrieved successfully', { bundles });
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to get bundles', error.message, 500);
    }
};
exports.getBundles = getBundles;
// 3. Dynamic Tier Discounts Calculator
const getTierDiscounts = async (req, res) => {
    try {
        const quantity = parseInt(req.query.quantity, 10) || 1;
        const subtotal = parseFloat(req.query.subtotal) || 0;
        const discountResult = smart_sales_service_1.SmartSalesService.calculateTierDiscount(quantity, subtotal);
        return (0, response_utils_1.sendSuccess)(res, 'Tier discount calculated', discountResult);
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to calculate tier discount', error.message, 500);
    }
};
exports.getTierDiscounts = getTierDiscounts;
// 4. Flash Deals
const getFlashDeals = async (_req, res) => {
    try {
        const deals = await smart_sales_service_1.SmartSalesService.getFlashDeals();
        return (0, response_utils_1.sendSuccess)(res, 'Flash deals retrieved', { deals });
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to get flash deals', error.message, 500);
    }
};
exports.getFlashDeals = getFlashDeals;
// 5. Upsells & Edition Upgrades
const getUpsells = async (req, res) => {
    try {
        const bookId = req.params.bookId;
        if (!bookId)
            return (0, response_utils_1.sendError)(res, 'Book ID is required', null, 400);
        const upsells = await smart_sales_service_1.SmartSalesService.getUpsellRecommendations(bookId);
        return (0, response_utils_1.sendSuccess)(res, 'Upsell recommendations retrieved', { upsells });
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to get upsells', error.message, 500);
    }
};
exports.getUpsells = getUpsells;
// 6. Cross-Sells for Cart / Checkout
const getCrossSells = async (req, res) => {
    try {
        const bookIdsParam = req.query.bookIds;
        const bookIds = bookIdsParam ? bookIdsParam.split(',') : [];
        const limit = req.query.limit ? parseInt(req.query.limit, 10) : 4;
        const crossSells = await smart_sales_service_1.SmartSalesService.getCrossSellRecommendations(bookIds, limit);
        return (0, response_utils_1.sendSuccess)(res, 'Cross-sell recommendations retrieved', { crossSells });
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to get cross-sells', error.message, 500);
    }
};
exports.getCrossSells = getCrossSells;
// 7. Festival Campaigns
const getCampaigns = async (_req, res) => {
    try {
        const campaigns = await smart_sales_service_1.SmartSalesService.getActiveCampaigns();
        return (0, response_utils_1.sendSuccess)(res, 'Active festival campaigns retrieved', { campaigns });
    }
    catch (error) {
        return (0, response_utils_1.sendError)(res, 'Failed to get campaigns', error.message, 500);
    }
};
exports.getCampaigns = getCampaigns;
//# sourceMappingURL=smart-sales.controller.js.map