"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MongooseInternalNoteRepository = void 0;
const InternalNoteModel_js_1 = require("../models/InternalNoteModel.js");
class MongooseInternalNoteRepository {
    async findById(id) {
        const doc = await InternalNoteModel_js_1.InternalNoteModel.findById(id).lean();
        return doc ? this.mapDocument(doc) : null;
    }
    async findByTicketId(ticketId) {
        const docs = await InternalNoteModel_js_1.InternalNoteModel.find({ ticketId }).sort({ createdAt: -1 }).lean();
        return docs.map((doc) => this.mapDocument(doc));
    }
    async create(input) {
        const doc = await InternalNoteModel_js_1.InternalNoteModel.create(input);
        return this.mapDocument(doc.toObject());
    }
    async update(id, text) {
        const doc = await InternalNoteModel_js_1.InternalNoteModel.findByIdAndUpdate(id, { text }, { new: true }).lean();
        return doc ? this.mapDocument(doc) : null;
    }
    async delete(id) {
        const result = await InternalNoteModel_js_1.InternalNoteModel.findByIdAndDelete(id);
        return result !== null;
    }
    mapDocument(doc) {
        return {
            id: doc._id.toString(),
            ticketId: doc.ticketId,
            agentId: doc.agentId,
            text: doc.text,
            createdAt: doc.createdAt,
            updatedAt: doc.updatedAt
        };
    }
}
exports.MongooseInternalNoteRepository = MongooseInternalNoteRepository;
