export type Role = "owner" | "admin" | "builder" | "operator" | "viewer";

export type RunStatus =
  | "pending"
  | "running"
  | "waiting_approval"
  | "succeeded"
  | "failed"
  | "cancelled";

export interface Workspace {
  id: string;
  name: string;
  slug: string;
  plan: string;
  role: Role | null;
  created_at: string;
}

export interface Tool {
  name: string;
  description: string;
  parameters: Record<string, unknown>;
  is_sensitive: boolean;
  scopes: string[];
}

export interface Agent {
  id: string;
  name: string;
  description: string;
  system_prompt: string;
  provider: string;
  model: string;
  tools: string[];
  memory_config: Record<string, unknown>;
  guardrails_json: Record<string, unknown>;
  is_active: boolean;
  created_at: string;
}

export interface Step {
  id: string;
  idx: number;
  type: string;
  name: string;
  status: string;
  input: Record<string, unknown>;
  output: Record<string, unknown>;
  error: string | null;
  tokens: number;
  created_at: string;
}

export interface Run {
  id: string;
  agent_id: string | null;
  workflow_id: string | null;
  status: RunStatus;
  input: Record<string, unknown>;
  output: Record<string, unknown> | null;
  error: string | null;
  total_tokens: number;
  total_steps: number;
  started_at: string | null;
  ended_at: string | null;
  created_at: string;
}

export interface Connector {
  id: string;
  type: string;
  name: string;
  config_json: Record<string, unknown>;
  status: string;
  status_detail: string | null;
  created_at: string;
}

export interface ConnectorType {
  type: string;
  title: string;
  config_schema: Record<string, unknown>;
  secret_schema: Record<string, unknown>;
  tools: string[];
}

export interface Approval {
  id: string;
  run_id: string;
  step_id: string | null;
  status: string;
  requested_tool: string;
  requested_args: Record<string, unknown>;
  summary: string;
  required_role: Role | null;
  expires_at: string | null;
  decided_by: string | null;
  decided_at: string | null;
  decision_reason: string | null;
  created_at: string;
}

export interface KnowledgeBase {
  id: string;
  name: string;
  description: string;
  embedding_provider: string;
  embedding_model: string;
  vector_collection: string;
  created_at: string;
}

export interface DocumentRow {
  id: string;
  knowledge_base_id: string;
  source: string;
  content_type: string;
  status: string;
  error: string | null;
  chunk_count: number;
  size_bytes: number;
  created_at: string;
}

export interface Workflow {
  id: string;
  name: string;
  description: string;
  definition_json: { nodes?: unknown[]; edges?: unknown[] };
  trigger_type: string;
  trigger_config: Record<string, unknown>;
  webhook_token: string | null;
  is_active: boolean;
  created_at: string;
}

export interface AuditEntry {
  id: string;
  seq: number;
  actor: string;
  action: string;
  target: string | null;
  metadata: Record<string, unknown>;
  hash: string;
  hash_prev: string | null;
  created_at: string;
}

export interface Member {
  id: string;
  user_id: string;
  email: string;
  name: string;
  role: Role;
  created_at: string;
}

export interface ApiKey {
  id: string;
  name: string;
  prefix: string;
  scopes: string[];
  last_used_at: string | null;
  revoked_at: string | null;
  created_at: string;
}
