import type { WorkspaceRecord } from "./domain";

export interface WorkbenchAuthConfig {
  mode?: "server" | "auto";
  username?: string;
  password?: string;
  sessionTtlMs?: number;
  ttlMs?: number;
}

export interface WorkbenchTimeoutConfig {
  apiTimeoutMs?: number;
  liveSurfaceTimeoutMs?: number;
  codeAgentTimeoutMs?: number;
  codeAgentTimeoutMsMinMs?: number;
  codeAgentSubmitTimeoutMs?: number;
  codeAgentSubmitTimeoutMsMinMs?: number;
  codeAgentCancelTimeoutMs?: number;
  gatewayShellTimeoutMs?: number;
}

export interface WorkbenchConfig {
  auth?: WorkbenchAuthConfig;
  timeouts?: WorkbenchTimeoutConfig;
  projectId?: string;
}

export interface WorkbenchWorkspaceBootstrap {
  projectId?: string;
  workspace?: WorkspaceRecord | null;
  consumed?: boolean;
}

export interface WorkbenchEarlyWorkspaceBootstrap {
  ok?: boolean;
  status?: number;
  data?: {
    authenticated?: boolean;
    user?: unknown;
    actor?: unknown;
    expiresAt?: string;
    projectId?: string;
    workspace?: WorkspaceRecord | null;
    workspaceStatus?: number | null;
    workspaceError?: unknown;
  } | null;
  error?: string;
  projectId?: string;
}

declare global {
  interface Window {
    HWLAB_CLOUD_WEB_CONFIG?: WorkbenchConfig;
    HWLAB_CLOUD_WEB_TIMEOUTS?: WorkbenchTimeoutConfig;
    HWLAB_CLOUD_WEB_WORKSPACE_BOOTSTRAP?: WorkbenchWorkspaceBootstrap;
    HWLAB_CLOUD_WEB_EARLY_WORKSPACE_BOOTSTRAP?: Promise<WorkbenchEarlyWorkspaceBootstrap>;
  }
}
