/**
 * Federation Agent Command Types
 *
 * Types for agent spawn commands sent via federation COMMAND messages.
 */

/**
 * Agent type options for spawning
 */
export type FederationAgentType = "worker" | "reviewer" | "tester";

/**
 * Agent status returned from remote instance
 */
export type FederationAgentStatus = "spawning" | "running" | "completed" | "failed" | "killed";

/**
 * Context for agent execution
 */
export interface FederationAgentContext {
  /** Git repository URL or path */
  repository: string;
  /** Git branch to work on */
  branch: string;
  /** Work items for the agent to complete */
  workItems: string[];
  /** Optional skills to load */
  skills?: string[];
  /** Optional instructions */
  instructions?: string;
}

/**
 * Options for spawning an agent
 */
export interface FederationAgentOptions {
  /** Enable Docker sandbox isolation */
  sandbox?: boolean;
  /** Timeout in milliseconds */
  timeout?: number;
  /** Maximum retry attempts */
  maxRetries?: number;
}

/**
 * Payload for agent.spawn command
 */
export interface SpawnAgentCommandPayload {
  /** Unique task identifier */
  taskId: string;
  /** Type of agent to spawn */
  agentType: FederationAgentType;
  /** Context for task execution */
  context: FederationAgentContext;
  /** Optional configuration */
  options?: FederationAgentOptions;
}

/**
 * Payload for agent.status command
 */
export interface AgentStatusCommandPayload {
  /** Unique agent identifier */
  agentId: string;
}

/**
 * Payload for agent.kill command
 */
export interface KillAgentCommandPayload {
  /** Unique agent identifier */
  agentId: string;
}

/**
 * Response data for agent.spawn command
 */
export interface SpawnAgentResponseData {
  /** Unique agent identifier */
  agentId: string;
  /** Current agent status */
  status: FederationAgentStatus;
  /** Timestamp when agent was spawned */
  spawnedAt: string;
}

/**
 * Response data for agent.status command
 */
export interface AgentStatusResponseData {
  /** Unique agent identifier */
  agentId: string;
  /** Task identifier */
  taskId: string;
  /** Current agent status */
  status: FederationAgentStatus;
  /** Timestamp when agent was spawned */
  spawnedAt: string;
  /** Timestamp when agent started (if running/completed) */
  startedAt?: string;
  /** Timestamp when agent completed (if completed/failed/killed) */
  completedAt?: string;
  /** Error message (if failed) */
  error?: string;
  /** Agent progress data */
  progress?: Record<string, unknown>;
}

/**
 * Response data for agent.kill command
 */
export interface KillAgentResponseData {
  /** Unique agent identifier */
  agentId: string;
  /** Status after kill operation */
  status: FederationAgentStatus;
  /** Timestamp when agent was killed */
  killedAt: string;
}

/**
 * Details about a federated agent
 */
export interface FederatedAgentDetails {
  /** Agent ID */
  agentId: string;
  /** Task ID */
  taskId: string;
  /** Remote instance ID where agent is running */
  remoteInstanceId: string;
  /** Connection ID used to spawn the agent */
  connectionId: string;
  /** Agent type */
  agentType: FederationAgentType;
  /** Current status */
  status: FederationAgentStatus;
  /** Spawn timestamp */
  spawnedAt: Date;
  /** Start timestamp */
  startedAt?: Date;
  /** Completion timestamp */
  completedAt?: Date;
  /** Error message if failed */
  error?: string;
  /** Context used to spawn agent */
  context: FederationAgentContext;
  /** Options used to spawn agent */
  options?: FederationAgentOptions;
}
