export type PaneRole = 'mainAgent' | 'dev' | 'shell' | 'git' | 'logs' | 'bridge' | 'custom';

export type WorkspacePresetId = 'agentSolo' | 'agentDev' | 'fullStack' | 'analysis' | 'v4Operating';

export type V4ProviderId = 'cloud' | 'v3_local' | 'byok';

export interface PaneDefinition {
  id: string;
  role: PaneRole;
  title: string;
  cwd: string;
  startupCommand?: string;
  isMain: boolean;
  sizeWeight: number;
}

export interface LayoutDefinition {
  direction: 'horizontal' | 'vertical';
  panes: PaneDefinition[];
}

export interface VigthoriaSettings {
  debugMode: boolean;
  autoApprove: boolean;
  autoSave: boolean;
  cliPath?: string;
}

export interface WorkspaceDefinition {
  id: string;
  name: string;
  rootPath: string;
  preset: WorkspacePresetId;
  layout: LayoutDefinition;
  vigthoria: VigthoriaSettings;
  updatedAt: string;
}

export type ToolsTabId = 'report' | 'community' | 'health' | 'hyperloop' | 'templates' | 'goa';

export interface VigthoriaAuthStatus {
  cliInstalled: boolean;
  hasToken: boolean;
  authenticated: boolean;
  email?: string | null;
  userId?: string | null;
  plan?: string | null;
  isAdmin: boolean;
  isMasterAdmin: boolean;
  apiUrl: string;
  modelsApiUrl: string;
  message: string;
}

export interface VigthoriaHttpResponse {
  ok: boolean;
  status: number;
  body: string;
}

export interface ByokStatus {
  hasApiKey: boolean;
  baseUrl: string;
  model: string;
  configPath: string;
}

export interface BundledCliStatus {
  version: string;
  available: boolean;
  installed: boolean;
  packagePath?: string | null;
}

export interface AppSettings {
  theme: string;
  defaultShell?: string;
  vigthoriaCliPath?: string;
  showReportPanel: boolean;
  lastWorkspaceId?: string;
  hyperloopUrl?: string;
  templateUrl?: string;
  comfortPromptEnabled?: boolean;
  goaAutoRoute?: boolean;
  toolsTab?: ToolsTabId;
}

export interface DirEntry {
  name: string;
  path: string;
  isDir: boolean;
}

export interface PtySpawnOptions {
  cwd?: string;
  shell?: string;
  cols: number;
  rows: number;
  env?: Record<string, string>;
  args?: string[];
}

export interface PtyOutputEvent {
  id: string;
  data: string;
}

export interface PtyExitEvent {
  id: string;
  code?: number;
}

export interface ActivePaneSession {
  paneId: string;
  ptyId: string;
  role: PaneRole;
  title: string;
  isMain: boolean;
  active: boolean;
}

export type AgentRunStatus = 'idle' | 'running' | 'complete' | 'failed';

export interface AgentRunState {
  status: AgentRunStatus;
  toolCount: number;
  currentTool?: string;
  iterationCount: number;
  elapsed?: string;
  reportMarkdown: string;
  summaryTitle: string;
  summarySections: string[];
  lastToolSuccess?: boolean;
}

export type DeckEventType =
  | 'agent_start'
  | 'tool_start'
  | 'tool_end'
  | 'report_ready'
  | 'run_complete'
  | 'run_summary';

export interface DeckEvent {
  type: DeckEventType;
  ts: number;
  tool?: string;
  target?: string;
  index?: number;
  success?: boolean;
  markdown?: string;
  iterations?: number;
  tools?: number;
  elapsed?: string;
  title?: string;
  sections?: string[];
}

export interface WorkspacePreset {
  id: WorkspacePresetId;
  name: string;
  description: string;
  build: (name: string, rootPath: string, options?: { v4Provider?: V4ProviderId }) => WorkspaceDefinition;
}


export interface V4RuntimeEvent {
  event: string;
  agent_id?: string;
  task?: string;
  payload?: Record<string, unknown>;
  ts?: number;
}

export type V4SubAgentStatus = 'spawned' | 'running' | 'finished' | 'error' | 'cancelled' | 'timeout';

export interface V4SubAgentState {
  agentId: string;
  task: string;
  status: V4SubAgentStatus;
  lastOutput?: string;
  outputLog: string[];
  updatedAt: number;
}

export interface WorkbenchUpdateInfo {
  currentVersion: string;
  latestVersion: string;
  updateAvailable: boolean;
  notes: string;
  artifactKind?: string | null;
  downloadUrl?: string | null;
  sha256?: string | null;
}
