/**
 * Canonical paths for AgenticMail's Telegram bridge service.
 *
 * All bridge state lives under `~/.agenticmail/telegram/` so it
 * co-exists cleanly with the rest of AgenticMail's per-user state
 * at `~/.agenticmail/`.
 */

import { join, dirname } from 'node:path';
import { homedir } from 'node:os';
import { fileURLToPath } from 'node:url';

// telegram-bridge/lib/paths.mjs → telegram-bridge/
export const BRIDGE_DIR = dirname(dirname(fileURLToPath(import.meta.url)));

// All bridge state lives under ~/.agenticmail/telegram/.
export const AM_DIR = join(homedir(), '.agenticmail');
export const TG_DIR = join(AM_DIR, 'telegram');

// Anthropic OAuth token — the Claude Code CLI's standard location, with a
// per-bridge override at ~/.agenticmail/telegram/anthropic-token so we don't
// trample the operator's interactive Claude session if they want to use a
// different account for the bot.
export const ANTHROPIC_TOKEN_FILE = join(TG_DIR, 'anthropic-token');

// Telegram bridge state files. Each file holds one piece of the
// bridge's per-install configuration / runtime state; the bridge
// reads them at boot and writes back on every poll / message.
export const TELEGRAM_TOKEN_FILE = join(TG_DIR, 'telegram-token');
export const TELEGRAM_ALLOWED_IDS_FILE = join(TG_DIR, 'telegram-allowed-ids');
export const TELEGRAM_OFFSET_FILE = join(TG_DIR, 'telegram-offset.json');
export const TELEGRAM_SESSIONS_FILE = join(TG_DIR, 'telegram-sessions.json');
export const TELEGRAM_WEBHOOK_CONFIG_FILE = join(TG_DIR, 'telegram-webhook.json');
export const TELEGRAM_MEDIA_DIR = join(TG_DIR, 'telegram-media');

// AgenticMail agent API key the bridge represents — written by
// `agenticmail setup` Step 8 when the user picks which agent should
// own the Telegram channel. When present, the bridge auto-generates
// an `mcp-config.json` that registers `@agenticmail/mcp` as an MCP
// server for every spawned `claude -p` turn, giving the bot access
// to the same toolset the dispatcher's workers have: persistent
// memory (mcp__agenticmail__memory_*), email send/receive, voice
// calls (call_phone), SMS, file storage, and so on. Absent → the
// bridge still works but the spawned Claude turns have no MCP tools
// and therefore no persistent memory.
export const AGENT_KEY_FILE = join(TG_DIR, 'agent-key');
// Legacy single-session file (the sessions.mjs library reads it on first boot;
// AgenticMail has no legacy to migrate, but the file is harmless if absent).
export const TELEGRAM_LEGACY_SESSION_FILE = join(TG_DIR, 'telegram-session-id');


// MCP config the spawned Claude turn should load. The bridge currently runs
// Claude without MCP servers (it has direct Telegram delivery, no MCP tools
// needed), but the path is kept so future per-turn tool wiring is one line.
export const MCP_CONFIG_FILE = join(TG_DIR, 'mcp-config.json');

// Env that every Claude spawn inherits — the published config
// (Opus 4.6 in fast mode, telemetry off, generous API timeout).
export const AM_CLAUDE_ENV = {
  ANTHROPIC_BASE_URL: 'https://api.anthropic.com',
  ANTHROPIC_MODEL: 'claude-opus-4-7[1m]',
  DISABLE_AUTOUPDATER: '1',
  CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
  DISABLE_TELEMETRY: '1',
  API_TIMEOUT_MS: '600000',
};
