export type FederatedHttpMethod = "GET" | "POST" | "PUT" | "DELETE";

export const PI_PACKAGE_MUTATION_PROXY_TIMEOUT_MS = 5 * 60_000;
export const SESSION_TREE_NAVIGATION_PROXY_TIMEOUT_MS = 5 * 60_000;

export interface FederatedHttpRouteSpec {
  method: FederatedHttpMethod;
  path: string;
  timeoutMs?: number;
}

export const FEDERATED_HTTP_ROUTES = [
  { method: "GET", path: "/pi-web/status" },
  { method: "GET", path: "/config" },
  { method: "PUT", path: "/config" },
  { method: "GET", path: "/plugins" },
  { method: "GET", path: "/pi-packages" },
  { method: "POST", path: "/pi-packages/install", timeoutMs: PI_PACKAGE_MUTATION_PROXY_TIMEOUT_MS },
  { method: "POST", path: "/pi-packages/remove", timeoutMs: PI_PACKAGE_MUTATION_PROXY_TIMEOUT_MS },
  { method: "POST", path: "/pi-packages/update", timeoutMs: PI_PACKAGE_MUTATION_PROXY_TIMEOUT_MS },
  { method: "GET", path: "/projects" },
  { method: "POST", path: "/projects" },
  { method: "DELETE", path: "/projects/:projectId" },
  { method: "GET", path: "/project-directories" },
  { method: "GET", path: "/projects/:projectId/workspaces" },
  { method: "DELETE", path: "/projects/:projectId/workspaces/:workspaceId" },
  { method: "GET", path: "/projects/:projectId/workspaces/:workspaceId/tree" },
  { method: "GET", path: "/projects/:projectId/workspaces/:workspaceId/file" },
  { method: "PUT", path: "/projects/:projectId/workspaces/:workspaceId/file" },
  { method: "DELETE", path: "/projects/:projectId/workspaces/:workspaceId/file" },
  { method: "POST", path: "/projects/:projectId/workspaces/:workspaceId/file/move" },
  { method: "GET", path: "/projects/:projectId/workspaces/:workspaceId/file/preview" },
  { method: "GET", path: "/projects/:projectId/workspaces/:workspaceId/files" },
  { method: "GET", path: "/projects/:projectId/workspaces/:workspaceId/git/status" },
  { method: "GET", path: "/projects/:projectId/workspaces/:workspaceId/git/diff" },
  { method: "GET", path: "/projects/:projectId/workspaces/:workspaceId/terminals" },
  { method: "POST", path: "/projects/:projectId/workspaces/:workspaceId/terminals" },
  { method: "DELETE", path: "/projects/:projectId/workspaces/:workspaceId/terminals" },
  { method: "POST", path: "/projects/:projectId/workspaces/:workspaceId/terminals/:terminalId/continue" },
  { method: "DELETE", path: "/projects/:projectId/workspaces/:workspaceId/terminals/:terminalId" },
  { method: "POST", path: "/projects/:projectId/workspaces/:workspaceId/terminal-command-runs" },
  { method: "GET", path: "/terminal-command-runs" },
  { method: "GET", path: "/terminal-command-runs/:runId" },
  { method: "POST", path: "/terminal-command-runs/:runId/cancel" },
  { method: "GET", path: "/files" },
  { method: "GET", path: "/activity" },
  { method: "GET", path: "/sessions" },
  { method: "POST", path: "/sessions" },
  { method: "GET", path: "/sessions/unread" },
  { method: "GET", path: "/sessions/notifications" },
  { method: "POST", path: "/sessions/cleanup/preview" },
  { method: "POST", path: "/sessions/cleanup" },
  { method: "POST", path: "/sessions/bulk/archive" },
  { method: "POST", path: "/sessions/bulk/delete-archived" },
  { method: "GET", path: "/sessions/:sessionId/messages" },
  { method: "GET", path: "/sessions/:sessionId/notifications" },
  { method: "POST", path: "/sessions/:sessionId/notifications/dismiss" },
  { method: "POST", path: "/sessions/:sessionId/notifications/dismiss-all" },
  { method: "POST", path: "/sessions/:sessionId/unread/acknowledge" },
  { method: "GET", path: "/sessions/:sessionId/status" },
  { method: "GET", path: "/sessions/:sessionId/stream-snapshot" },
  { method: "GET", path: "/sessions/:sessionId/models" },
  { method: "POST", path: "/sessions/:sessionId/model" },
  { method: "POST", path: "/sessions/:sessionId/model/cycle" },
  { method: "GET", path: "/sessions/:sessionId/thinking-levels" },
  { method: "POST", path: "/sessions/:sessionId/thinking-level" },
  { method: "POST", path: "/sessions/:sessionId/thinking-level/cycle" },
  { method: "GET", path: "/sessions/:sessionId/commands" },
  { method: "POST", path: "/sessions/:sessionId/prompt" },
  { method: "POST", path: "/sessions/:sessionId/queue/clear" },
  { method: "POST", path: "/sessions/:sessionId/ask/submit" },
  { method: "POST", path: "/sessions/:sessionId/ask/cancel" },
  { method: "POST", path: "/sessions/:sessionId/warnings/dismiss" },
  { method: "POST", path: "/sessions/:sessionId/attachments" },
  { method: "POST", path: "/sessions/:sessionId/shell" },
  { method: "POST", path: "/sessions/:sessionId/commands/run" },
  { method: "POST", path: "/sessions/:sessionId/commands/respond" },
  { method: "POST", path: "/sessions/:sessionId/tree/navigate", timeoutMs: SESSION_TREE_NAVIGATION_PROXY_TIMEOUT_MS },
  { method: "POST", path: "/sessions/:sessionId/abort" },
  { method: "POST", path: "/sessions/:sessionId/stop" },
  { method: "POST", path: "/sessions/:sessionId/archive" },
  { method: "POST", path: "/sessions/:sessionId/archive-tree" },
  { method: "POST", path: "/sessions/:sessionId/restore" },
  { method: "DELETE", path: "/sessions/:sessionId" },
  { method: "POST", path: "/sessions/:sessionId/reload" },
  { method: "POST", path: "/sessions/:sessionId/detach-parent" },
  { method: "GET", path: "/auth/providers" },
  { method: "POST", path: "/auth/api-key" },
  { method: "POST", path: "/auth/api-key/interactive" },
  { method: "POST", path: "/auth/logout" },
  { method: "POST", path: "/auth/oauth" },
  { method: "GET", path: "/auth/oauth/:flowId" },
  { method: "POST", path: "/auth/oauth/:flowId/respond" },
  { method: "POST", path: "/auth/oauth/:flowId/cancel" },
] as const satisfies readonly FederatedHttpRouteSpec[];

export const FEDERATED_WEBSOCKET_ROUTES = [
  "/events",
  "/sessions/events",
  "/sessions/:sessionId/events",
  "/projects/:projectId/workspaces/:workspaceId/terminals/:terminalId/socket",
] as const satisfies readonly string[];
