import { EventBus } from './event-bus.js';
import { SessionManager } from '../services/session-manager.js';
import { CommitMessageService } from '../services/commit-message.service.js';
import { NotificationService } from '../services/notifications/index.js';
import { TaskCleanupService } from '../services/task-cleanup.service.js';
import { WorkspaceGitWatcherService } from '../services/workspace-git-watcher.service.js';
import { prisma } from '../utils/index.js';
let eventBus = null;
let sessionManager = null;
let terminalManager = null;
let commitMessageService = null;
let notificationService = null;
let taskCleanupService = null;
let workspaceGitWatcherService = null;
export function getEventBus() {
    if (!eventBus) {
        eventBus = new EventBus();
    }
    return eventBus;
}
export function getSessionManager() {
    if (!sessionManager) {
        sessionManager = new SessionManager(getEventBus());
    }
    return sessionManager;
}
export function getCommitMessageService() {
    if (!commitMessageService) {
        commitMessageService = new CommitMessageService();
    }
    return commitMessageService;
}
export function getTaskCleanupService() {
    if (!taskCleanupService) {
        taskCleanupService = new TaskCleanupService(getSessionManager(), getWorkspaceGitWatcherService());
    }
    return taskCleanupService;
}
export function getWorkspaceGitWatcherService() {
    if (!workspaceGitWatcherService) {
        workspaceGitWatcherService = new WorkspaceGitWatcherService(getEventBus());
    }
    return workspaceGitWatcherService;
}
export async function getTerminalManager() {
    if (!terminalManager) {
        const { TerminalManager: TM } = await import('../services/terminal-manager.js');
        terminalManager = new TM(getEventBus());
    }
    return terminalManager;
}
export function getNotificationService() {
    if (!notificationService) {
        notificationService = new NotificationService();
        // 监听 task:updated，当任务进入 IN_REVIEW 时发送通知
        getEventBus().on('task:updated', ({ taskId, status }) => {
            if (status !== 'IN_REVIEW')
                return;
            prisma.task.findUnique({
                where: { id: taskId },
                select: { title: true, projectId: true },
            })
                .then((task) => {
                notificationService.notify({
                    type: 'task_in_review',
                    title: 'Agent Tower', // 模板里会覆盖
                    body: '', // 模板里会覆盖
                    metadata: {
                        taskId,
                        taskTitle: task?.title ?? taskId,
                        projectId: task?.projectId ?? '',
                    },
                });
            })
                .catch((err) => {
                console.error('[NotificationService] Failed to fetch task for notification:', err);
            });
        });
    }
    return notificationService;
}
//# sourceMappingURL=container.js.map