// Project and Group configuration types

import type { ProviderId } from './agent';
import type { ProjectId, GroupId, AgentId } from './ids';

// ── Anchor budget ────────────────────────────────────────────────────────────

export type AnchorBudgetScale = 'small' | 'medium' | 'large' | 'full';

// ── Wake strategy ────────────────────────────────────────────────────────────

export type WakeStrategy = 'persistent' | 'on-demand' | 'smart';

// ── Agent roles ──────────────────────────────────────────────────────────────

export type GroupAgentRole = 'manager' | 'architect' | 'tester' | 'reviewer';

// ── Project configuration ────────────────────────────────────────────────────

export interface ProjectConfig {
  id: ProjectId;
  name: string;
  identifier: string;
  description: string;
  icon: string;
  cwd: string;
  profile: string;
  enabled: boolean;
  /** Agent provider for this project (defaults to 'claude') */
  provider?: ProviderId;
  /** Model override. Falls back to provider default. */
  model?: string;
  /** When true, agents for this project use git worktrees for isolation */
  useWorktrees?: boolean;
  /** When true, sidecar process is sandboxed via Landlock */
  sandboxEnabled?: boolean;
  /** Shell execution mode for AI agents */
  autonomousMode?: 'restricted' | 'autonomous';
  /** Anchor token budget scale (defaults to 'medium' = 6K tokens) */
  anchorBudgetScale?: AnchorBudgetScale;
  /** Stall detection threshold in minutes (defaults to 15) */
  stallThresholdMin?: number;
  /** True for Tier 1 management agents rendered as project boxes */
  isAgent?: boolean;
  /** Agent role (manager/architect/tester/reviewer) -- only when isAgent */
  agentRole?: GroupAgentRole;
  /** System prompt injected at session start -- only when isAgent */
  systemPrompt?: string;
}

// ── Group-level agent configuration ──────────────────────────────────────────

export interface GroupAgentConfig {
  id: AgentId;
  name: string;
  role: GroupAgentRole;
  provider?: ProviderId;
  model?: string;
  cwd?: string;
  systemPrompt?: string;
  enabled: boolean;
  /** Auto-wake interval in minutes (Manager only, default 3) */
  wakeIntervalMin?: number;
  /** Wake strategy */
  wakeStrategy?: WakeStrategy;
  /** Wake threshold 0..1 for smart strategy (default 0.5) */
  wakeThreshold?: number;
  /** Shell execution mode */
  autonomousMode?: 'restricted' | 'autonomous';
}

// ── Group configuration ──────────────────────────────────────────────────────

export interface GroupConfig {
  id: GroupId;
  name: string;
  projects: ProjectConfig[];
  /** Group-level orchestration agents (Tier 1) */
  agents?: GroupAgentConfig[];
}

// ── Groups file (persisted to disk) ──────────────────────────────────────────

export interface GroupsFile {
  version: number;
  groups: GroupConfig[];
  activeGroupId: GroupId;
}
