/**
 * TypeScript interfaces for Automation & Agents module.
 * Matches backend schemas from /api/v1/automation and /api/v1/agents.
 */

export interface AutomationCondition {
  field: string;
  operator: string;
  value: string;
}

export interface AutomationAction {
  type: 'api_call' | 'notification' | 'workflow_start';
  config: Record<string, unknown>;
}

export interface AutomationDefinition {
  id: string;
  name: string;
  description?: string;
  trigger_type: 'event' | 'schedule' | 'manual';
  trigger_config?: Record<string, unknown>;
  conditions?: AutomationCondition[];
  actions?: AutomationAction[];
  active: boolean;
  dry_run: boolean;
  created_at: string;
  updated_at: string;
}

export interface AutomationRun {
  id: string;
  automation_id: string;
  status: 'running' | 'completed' | 'failed' | 'cancelled';
  started_at: string;
  completed_at?: string;
  result?: unknown;
  error?: string;
}

export interface AutomationVersion {
  id: string;
  automation_id: string;
  version: number;
  created_at: string;
  data: AutomationDefinition;
}

export interface AgentDefinition {
  id: string;
  name: string;
  description?: string;
  model: string;
  system_prompt?: string;
  tools?: string[];
  heartbeat_interval: number;
  mode: 'proactive' | 'reactive';
  max_executions_per_hour: number;
  max_duration: number;
  budget_limit: number;
  active: boolean;
  created_at: string;
  updated_at: string;
}

export interface AgentRun {
  id: string;
  agent_id: string;
  status: 'running' | 'completed' | 'failed' | 'cancelled';
  started_at: string;
  completed_at?: string;
  result?: unknown;
  error?: string;
}

export interface AgentVersion {
  id: string;
  agent_id: string;
  version: number;
  created_at: string;
  data: AgentDefinition;
}

export interface AgentTool {
  name: string;
  description: string;
}

export interface AutomationSettings {
  default_llm_model: string;
  heartbeat_default_interval: number;
  max_concurrent_agents: number;
  log_level: 'debug' | 'info' | 'warning' | 'error';
}

export interface MiniAppDef {
  app_id: string;
  name: string;
  icon: string;
  description: string;
  plugin_name: string;
  render_schema: Record<string, unknown>;
}

export type RecentRun = (AutomationRun | AgentRun) & {
  type: 'automation' | 'agent';
  name?: string;
};
