import { compactJson, compactError } from './output-formatter.js';
import { handleRegister, handleHeartbeat, handleLock, handleUnlock, handleStatus, handleResolveConflict, } from './orchestrate/session-handlers.js';
import { handleBrief, handleJournal } from './orchestrate/journal-brief-handlers.js';
// ---------------------------------------------------------------------------
// Main handler
// ---------------------------------------------------------------------------
export async function handleOrchestrate(params) {
    const { projectId, action, sessionId, specId, resourcePath, limit, experienceLevel, lockTtlMinutes, fileOwnership, journalAction, eventType, commitHash, } = params;
    try {
        switch (action) {
            case 'register':
                return await handleRegister(projectId, sessionId, specId, fileOwnership);
            case 'heartbeat':
                return await handleHeartbeat(projectId, sessionId, lockTtlMinutes);
            case 'lock':
                return await handleLock(projectId, sessionId, resourcePath, specId, lockTtlMinutes, fileOwnership);
            case 'unlock':
                return await handleUnlock(projectId, sessionId, resourcePath, specId);
            case 'status':
                return await handleStatus(projectId, experienceLevel);
            case 'resolve-conflict':
                return await handleResolveConflict(projectId, sessionId, specId, resourcePath);
            case 'brief':
                return await handleBrief(projectId, experienceLevel);
            case 'journal':
                return await handleJournal(sessionId, journalAction, eventType, specId, commitHash, limit ?? 10);
            default:
                return compactError(`Unknown orchestration action: ${String(action)}`);
        }
    }
    catch (err) {
        const message = err instanceof Error ? err.message : String(err);
        return compactError(compactJson({ error: message, action }));
    }
}
//# sourceMappingURL=orchestrate.js.map