"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSupportSearchController = createSupportSearchController;
function createSupportSearchController(messageService, ticketService, logger) {
    return {
        search: async (req, res) => {
            try {
                const { q, ticketIds } = req.query;
                const query = String(q ?? "");
                if (!query || query.length < 2) {
                    res.json({ success: true, data: { messages: [], tickets: [] } });
                    return;
                }
                const parsedTicketIds = ticketIds ? String(ticketIds).split(",") : undefined;
                const [messages, tickets] = await Promise.all([
                    messageService.searchMessages(query, parsedTicketIds),
                    ticketService.listTickets({ search: query, limit: 50 })
                ]);
                res.json({ success: true, data: { messages, tickets } });
            }
            catch (error) {
                logger.error("Failed to search support.", { error: error instanceof Error ? error.message : String(error) });
                res.status(500).json({ success: false, error: "Failed to search." });
            }
        }
    };
}
