import os from 'os';

export const DEFAULT_AUTOMEM_API_URL = 'http://127.0.0.1:8001';

export function buildClaudeDesktopSnippet(endpointVar = '${AUTOMEM_API_URL}', apiKeyVar = '${AUTOMEM_API_KEY}') {
  return `{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@verygoodplugins/mcp-automem"],
      "env": {
        "AUTOMEM_API_URL": "${endpointVar}",
        "AUTOMEM_API_KEY": "${apiKeyVar}"
      }
    }
  }
}`;
}

export function buildClaudeCodeExport(endpoint = DEFAULT_AUTOMEM_API_URL, apiKey = 'your-auto-mem-api-key') {
  return [
    'claude mcp add memory "npx -y @verygoodplugins/mcp-automem"',
    `export AUTOMEM_API_URL="${endpoint}"`,
    `export AUTOMEM_API_KEY="${apiKey}"`
  ].join(os.EOL);
}

export function buildHermesSnippet(endpoint = '${AUTOMEM_API_URL}', apiKey = '${AUTOMEM_API_KEY}') {
  // YAML form for ~/.hermes/config.yaml under the `mcp_servers` key.
  return `mcp_servers:
  automem:
    command: npx
    args:
      - -y
      - "@verygoodplugins/mcp-automem"
    env:
      AUTOMEM_API_URL: "${endpoint}"
      AUTOMEM_API_KEY: "${apiKey}"
    tools:
      include:
        - recall_memory
        - store_memory
        - associate_memories
        - update_memory
        - check_database_health
      resources: false
      prompts: false
    sampling:
      enabled: false`;
}

export function buildMcpConfigJson(endpoint: string, apiKey: string) {
  return {
    mcpServers: {
      memory: {
        command: 'npx',
        args: ['@verygoodplugins/mcp-automem'],
        env: {
          AUTOMEM_API_URL: endpoint,
          AUTOMEM_API_KEY: apiKey,
        },
      },
    },
  };
}

export function buildSummaryInstructions(endpoint: string, apiKeyProvided: boolean) {
  const lines: string[] = [
    '',
    'Next steps:',
    '  • Add the Claude Desktop snippet below to claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/claude_desktop_config.json)',
    '  • Or run the Claude Code command shown to register the server in Claude Code',
    apiKeyProvided ? '  • Environment variables updated in your .env file' : '  • Remember to set AUTOMEM_API_KEY before connecting (no key provided during setup)',
    `  • Endpoint configured to ${endpoint}`,
    ''
  ];

  return lines.join('\n');
}
