"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MongooseSupportSettingsRepository = void 0;
const SupportSettingsModel_js_1 = require("../models/SupportSettingsModel.js");
const DEFAULT_AUTO_MESSAGE_OPEN = "Your support request has been received. A support agent will assist you shortly.";
const DEFAULT_AUTO_MESSAGE_CLOSE = "Your support ticket has been closed. If you need further assistance, feel free to open a new chat.";
class MongooseSupportSettingsRepository {
    async get() {
        const doc = await SupportSettingsModel_js_1.SupportSettingsModel.findOne().lean();
        return doc ? this.mapDocument(doc) : null;
    }
    async create(input) {
        const doc = await SupportSettingsModel_js_1.SupportSettingsModel.create(input);
        return this.mapDocument(doc.toObject());
    }
    async update(input) {
        const doc = await SupportSettingsModel_js_1.SupportSettingsModel.findOneAndUpdate({}, input, { new: true }).lean();
        return doc ? this.mapDocument(doc) : null;
    }
    async getOrCreate() {
        const existing = await this.get();
        if (existing)
            return existing;
        return this.create({
            welcomeMessage: "Hello {{firstName}}\n\nWelcome to Support.\n\nPlease describe your issue.\n\nYou may also send:\n\n• Images\n• Documents\n• Videos\n• Voice Notes\n\nA support ticket will be created automatically.",
            aiEnabled: false,
            aiConfidenceThreshold: 0.6,
            assignmentMode: "ROUND_ROBIN",
            maxOpenTickets: 100,
            maxTicketsPerUser: 3,
            businessHours: [],
            autoReplies: [],
            cannedResponses: [],
            autoMessageOnTicketOpenEnabled: true,
            autoMessageOnTicketOpenText: DEFAULT_AUTO_MESSAGE_OPEN,
            autoMessageOnTicketOpenButtons: [],
            autoMessageOnTicketCloseEnabled: true,
            autoMessageOnTicketCloseText: DEFAULT_AUTO_MESSAGE_CLOSE,
            autoMessageOnTicketCloseButtons: []
        });
    }
    mapDocument(doc) {
        return {
            id: doc._id.toString(),
            welcomeMessage: doc.welcomeMessage,
            aiEnabled: doc.aiEnabled,
            aiConfidenceThreshold: doc.aiConfidenceThreshold,
            assignmentMode: doc.assignmentMode,
            maxOpenTickets: doc.maxOpenTickets,
            maxTicketsPerUser: doc.maxTicketsPerUser,
            businessHours: doc.businessHours,
            autoReplies: doc.autoReplies,
            cannedResponses: doc.cannedResponses,
            autoMessageOnTicketOpenEnabled: doc.autoMessageOnTicketOpenEnabled ?? true,
            autoMessageOnTicketOpenText: doc.autoMessageOnTicketOpenText ?? DEFAULT_AUTO_MESSAGE_OPEN,
            autoMessageOnTicketOpenButtons: doc.autoMessageOnTicketOpenButtons ?? [],
            autoMessageOnTicketCloseEnabled: doc.autoMessageOnTicketCloseEnabled ?? true,
            autoMessageOnTicketCloseText: doc.autoMessageOnTicketCloseText ?? DEFAULT_AUTO_MESSAGE_CLOSE,
            autoMessageOnTicketCloseButtons: doc.autoMessageOnTicketCloseButtons ?? [],
            createdAt: doc.createdAt,
            updatedAt: doc.updatedAt
        };
    }
}
exports.MongooseSupportSettingsRepository = MongooseSupportSettingsRepository;
