import { getMemoryStatus, setupOpenMemory, setupMem0Cloud, resetMemoryConfig, } from '../engine/memory-config-generator.js';
export async function handleConfigureMemory(input) {
    const { projectPath, action, apiKey } = input;
    switch (action) {
        case 'setup-openmemory': {
            const configPath = await setupOpenMemory(projectPath);
            const lines = [
                'OpenMemory (mem0) configured successfully.',
                '',
                `Config written to: ${configPath}`,
                '',
                'The following MCP server entry was added to .claude.json:',
                '```json',
                JSON.stringify({
                    mcpServers: {
                        memory: {
                            command: 'npx',
                            args: ['-y', '@mem0/mcp'],
                        },
                    },
                }, null, 2),
                '```',
                '',
                'Restart Claude Code to activate the memory MCP server.',
            ];
            return { content: [{ type: 'text', text: lines.join('\n') }] };
        }
        case 'setup-mem0-cloud': {
            if (!apiKey) {
                return {
                    content: [
                        {
                            type: 'text',
                            text: 'Error: apiKey is required for setup-mem0-cloud action. Get your API key from https://app.mem0.ai',
                        },
                    ],
                    isError: true,
                };
            }
            const configPath = await setupMem0Cloud(projectPath, apiKey);
            const lines = [
                'Mem0 Cloud configured successfully.',
                '',
                `Config written to: ${configPath}`,
                '',
                'The memory MCP server with your API key has been added to .claude.json.',
                '',
                'Restart Claude Code to activate the memory MCP server.',
            ];
            return { content: [{ type: 'text', text: lines.join('\n') }] };
        }
        case 'status': {
            const status = await getMemoryStatus(projectPath);
            const lines = [
                'Memory Configuration Status',
                '===========================',
                '',
                `Provider: ${status.provider}`,
                `Connected: ${String(status.connected)}`,
                `Memory count: ${String(status.memoryCount)}`,
                `Config path: ${status.configPath}`,
            ];
            return {
                content: [{ type: 'text', text: lines.join('\n') }],
                structuredContent: { ...status },
            };
        }
        case 'reset': {
            const configPath = await resetMemoryConfig(projectPath);
            return {
                content: [
                    {
                        type: 'text',
                        text: `Memory MCP configuration removed from ${configPath}.\n\nRestart Claude Code to deactivate the memory server.`,
                    },
                ],
            };
        }
        default: {
            const _never = action;
            return {
                content: [
                    {
                        type: 'text',
                        text: `Unknown action: ${String(_never)}. Valid actions: setup-openmemory, setup-mem0-cloud, status, reset`,
                    },
                ],
                isError: true,
            };
        }
    }
}
export async function handleMemoryStatus(input) {
    const { projectPath } = input;
    const status = await getMemoryStatus(projectPath);
    const lines = [
        'Memory Status',
        '=============',
        '',
        `Provider: ${status.provider}`,
        `Connected: ${String(status.connected)}`,
        `Memory count: ${String(status.memoryCount)}`,
        `Config path: ${status.configPath}`,
    ];
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
        structuredContent: { ...status },
    };
}
//# sourceMappingURL=memory-config-handler.js.map