"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSupportModule = createSupportModule;
const index_js_1 = require("./infrastructure/database/repositories/index.js");
const index_js_2 = require("./application/services/index.js");
const SupportEventBus_js_1 = require("./infrastructure/events/SupportEventBus.js");
const index_js_3 = require("./infrastructure/ai/index.js");
const SupportBot_js_1 = require("./infrastructure/telegram/SupportBot.js");
function createSupportModule(config, logger) {
    const eventBus = new SupportEventBus_js_1.SupportEventBus();
    const userRepository = new index_js_1.MongooseSupportUserRepository();
    const ticketRepository = new index_js_1.MongooseSupportTicketRepository();
    const messageRepository = new index_js_1.MongooseSupportMessageRepository();
    const agentRepository = new index_js_1.MongooseSupportAgentRepository();
    const settingsRepository = new index_js_1.MongooseSupportSettingsRepository();
    const noteRepository = new index_js_1.MongooseInternalNoteRepository();
    const userService = new index_js_2.SupportUserService(userRepository, logger);
    const ticketService = new index_js_2.SupportTicketService(ticketRepository, messageRepository, settingsRepository, logger);
    const messageService = new index_js_2.SupportMessageService(messageRepository, ticketRepository, logger);
    const agentService = new index_js_2.SupportAgentService(agentRepository, logger);
    const settingsService = new index_js_2.SupportSettingsService(settingsRepository, logger);
    const assignmentService = new index_js_2.SupportAssignmentService(agentRepository, settingsRepository, logger);
    const noteService = new index_js_2.InternalNoteService(noteRepository, logger);
    const aiProvider = index_js_3.AIProviderFactory.create({
        provider: config.supportAiProvider ?? "rule",
        apiKey: config.supportAiApiKey,
        model: config.supportAiModel,
        endpoint: config.supportAiEndpoint,
        confidenceThreshold: config.supportAiConfidenceThreshold
    });
    let botRef;
    const sendToUser = async (payload) => {
        await botRef?.sendMessageToUser(payload);
    };
    const orchestrator = new index_js_2.SupportOrchestrator(userService, ticketService, messageService, agentService, settingsService, assignmentService, aiProvider, eventBus, config, logger, sendToUser);
    const bot = new SupportBot_js_1.SupportBot({ config, logger, orchestrator, eventBus });
    botRef = bot;
    return {
        logger,
        eventBus,
        userService,
        ticketService,
        messageService,
        agentService,
        settingsService,
        assignmentService,
        noteService,
        orchestrator,
        bot
    };
}
