import { handleSave, handleLoad, handleList, handleDelete, handleCleanup, handleAddNote, handleGetContext, handleDocHealth, } from './manage-context/handlers.js';
// ---------------------------------------------------------------------------
// Main handler
// ---------------------------------------------------------------------------
export async function handleManageContext(params) {
    const { projectId, action, key, content, ttlDays, tags, specId, filterByTag, filterBySpecId } = params;
    switch (action) {
        case 'save': {
            if (!key) {
                return {
                    content: [
                        {
                            type: 'text',
                            text: JSON.stringify({ error: "Parameter 'key' is required for save action" }, null, 2),
                        },
                    ],
                    isError: true,
                };
            }
            if (!content) {
                return {
                    content: [
                        {
                            type: 'text',
                            text: JSON.stringify({ error: "Parameter 'content' is required for save action" }, null, 2),
                        },
                    ],
                    isError: true,
                };
            }
            return handleSave(projectId, key, content, ttlDays, tags, specId);
        }
        case 'load': {
            if (!key) {
                return {
                    content: [
                        {
                            type: 'text',
                            text: JSON.stringify({ error: "Parameter 'key' is required for load action" }, null, 2),
                        },
                    ],
                    isError: true,
                };
            }
            return handleLoad(projectId, key);
        }
        case 'list':
            return handleList(projectId, filterByTag, filterBySpecId);
        case 'delete': {
            if (!key) {
                return {
                    content: [
                        {
                            type: 'text',
                            text: JSON.stringify({ error: "Parameter 'key' is required for delete action" }, null, 2),
                        },
                    ],
                    isError: true,
                };
            }
            return handleDelete(projectId, key);
        }
        case 'cleanup':
            return handleCleanup(projectId);
        case 'add-note': {
            if (!key) {
                return {
                    content: [
                        {
                            type: 'text',
                            text: JSON.stringify({ error: "Parameter 'key' is required for add-note action" }, null, 2),
                        },
                    ],
                    isError: true,
                };
            }
            if (!content) {
                return {
                    content: [
                        {
                            type: 'text',
                            text: JSON.stringify({ error: "Parameter 'content' is required for add-note action" }, null, 2),
                        },
                    ],
                    isError: true,
                };
            }
            return handleAddNote(projectId, key, content, tags ?? [], specId);
        }
        case 'get-context':
            return handleGetContext(projectId);
        case 'doc-health':
            return handleDocHealth(projectId);
        default:
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({ error: `Unknown action: ${String(action)}` }, null, 2),
                    },
                ],
                isError: true,
            };
    }
}
//# sourceMappingURL=manage-context.js.map