"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createInternalNoteController = createInternalNoteController;
function createInternalNoteController(noteService, logger) {
    return {
        listByTicket: async (req, res) => {
            try {
                const notes = await noteService.getNotesByTicketId(String(req.params.ticketId));
                res.json({ success: true, data: notes });
            }
            catch (error) {
                logger.error("Failed to list internal notes.", { error: error instanceof Error ? error.message : String(error) });
                res.status(500).json({ success: false, error: "Failed to list notes." });
            }
        },
        create: async (req, res) => {
            try {
                const { ticketId, text } = req.body;
                const agentId = req.adminUser?.id ?? "admin";
                const note = await noteService.createNote({ ticketId, agentId, text });
                res.status(201).json({ success: true, data: note });
            }
            catch (error) {
                logger.error("Failed to create internal note.", { error: error instanceof Error ? error.message : String(error) });
                res.status(500).json({ success: false, error: "Failed to create note." });
            }
        },
        update: async (req, res) => {
            try {
                const note = await noteService.updateNote(String(req.params.id), req.body.text);
                if (!note) {
                    res.status(404).json({ success: false, error: "Note not found." });
                    return;
                }
                res.json({ success: true, data: note });
            }
            catch (error) {
                logger.error("Failed to update internal note.", { error: error instanceof Error ? error.message : String(error) });
                res.status(500).json({ success: false, error: "Failed to update note." });
            }
        },
        delete: async (req, res) => {
            try {
                const success = await noteService.deleteNote(String(req.params.id));
                if (!success) {
                    res.status(404).json({ success: false, error: "Note not found." });
                    return;
                }
                res.json({ success: true });
            }
            catch (error) {
                logger.error("Failed to delete internal note.", { error: error instanceof Error ? error.message : String(error) });
                res.status(500).json({ success: false, error: "Failed to delete note." });
            }
        }
    };
}
