/**
 * AgentType API Types
 *
 * These types mirror the backend Pydantic schemas for AgentType entities.
 * Used for type-safe API communication with the agent-types endpoints.
 */

/**
 * Category classification for agent types
 */
export type AgentTypeCategory =
  | 'development'
  | 'design'
  | 'quality'
  | 'operations'
  | 'ai_ml'
  | 'data'
  | 'leadership'
  | 'domain_expert';

/**
 * Metadata for each category including display label and description
 */
export const CATEGORY_METADATA: Record<
  AgentTypeCategory,
  { label: string; description: string; color: string }
> = {
  development: {
    label: 'Development',
    description: 'Product, project, and engineering roles',
    color: '#3B82F6',
  },
  design: {
    label: 'Design',
    description: 'UI/UX and design research',
    color: '#EC4899',
  },
  quality: {
    label: 'Quality',
    description: 'QA and security assurance',
    color: '#10B981',
  },
  operations: {
    label: 'Operations',
    description: 'DevOps and MLOps engineering',
    color: '#F59E0B',
  },
  ai_ml: {
    label: 'AI & ML',
    description: 'Machine learning specialists',
    color: '#8B5CF6',
  },
  data: {
    label: 'Data',
    description: 'Data science and engineering',
    color: '#06B6D4',
  },
  leadership: {
    label: 'Leadership',
    description: 'Technical leadership and facilitation',
    color: '#F97316',
  },
  domain_expert: {
    label: 'Domain Experts',
    description: 'Industry and domain specialists',
    color: '#84CC16',
  },
};

/**
 * Base agent type fields shared across create, update, and response schemas
 */
export interface AgentTypeBase {
  name: string;
  slug: string;
  description?: string | null;
  expertise: string[];
  personality_prompt: string;
  primary_model: string;
  fallback_models: string[];
  model_params: Record<string, unknown>;
  mcp_servers: string[];
  tool_permissions: Record<string, unknown>;
  is_active: boolean;
  // Category and display fields
  category?: AgentTypeCategory | null;
  icon?: string | null;
  color?: string | null;
  sort_order: number;
  typical_tasks: string[];
  collaboration_hints: string[];
}

/**
 * Schema for creating a new agent type
 */
export interface AgentTypeCreate {
  name: string;
  slug: string;
  description?: string | null;
  expertise?: string[];
  personality_prompt: string;
  primary_model: string;
  fallback_models?: string[];
  model_params?: Record<string, unknown>;
  mcp_servers?: string[];
  tool_permissions?: Record<string, unknown>;
  is_active?: boolean;
  // Category and display fields
  category?: AgentTypeCategory | null;
  icon?: string | null;
  color?: string | null;
  sort_order?: number;
  typical_tasks?: string[];
  collaboration_hints?: string[];
}

/**
 * Schema for updating an existing agent type
 */
export interface AgentTypeUpdate {
  name?: string | null;
  slug?: string | null;
  description?: string | null;
  expertise?: string[] | null;
  personality_prompt?: string | null;
  primary_model?: string | null;
  fallback_models?: string[] | null;
  model_params?: Record<string, unknown> | null;
  mcp_servers?: string[] | null;
  tool_permissions?: Record<string, unknown> | null;
  is_active?: boolean | null;
  // Category and display fields
  category?: AgentTypeCategory | null;
  icon?: string | null;
  color?: string | null;
  sort_order?: number | null;
  typical_tasks?: string[] | null;
  collaboration_hints?: string[] | null;
}

/**
 * Schema for agent type API responses
 */
export interface AgentTypeResponse {
  id: string;
  name: string;
  slug: string;
  description: string | null;
  expertise: string[];
  personality_prompt: string;
  primary_model: string;
  fallback_models: string[];
  model_params: Record<string, unknown>;
  mcp_servers: string[];
  tool_permissions: Record<string, unknown>;
  is_active: boolean;
  // Category and display fields
  category: AgentTypeCategory | null;
  icon: string | null;
  color: string | null;
  sort_order: number;
  typical_tasks: string[];
  collaboration_hints: string[];
  created_at: string;
  updated_at: string;
  instance_count: number;
}

/**
 * Pagination metadata for list responses
 */
export interface PaginationMeta {
  total: number;
  page: number;
  page_size: number;
  total_pages: number;
  has_next: boolean;
  has_prev: boolean;
}

/**
 * Schema for paginated agent type list responses
 */
export interface AgentTypeListResponse {
  data: AgentTypeResponse[];
  pagination: PaginationMeta;
}

/**
 * Query parameters for listing agent types
 */
export interface AgentTypeListParams {
  page?: number;
  limit?: number;
  is_active?: boolean;
  category?: AgentTypeCategory;
  search?: string;
}

/**
 * Response type for grouped agent types by category
 */
export type AgentTypeGroupedResponse = Record<string, AgentTypeResponse[]>;

/**
 * Model parameter configuration with typed fields
 */
export interface ModelParams {
  temperature?: number;
  max_tokens?: number;
  top_p?: number;
  [key: string]: unknown;
}

/**
 * MCP permission scope configuration
 */
export interface McpPermission {
  id: string;
  name: string;
  enabled: boolean;
  scopes: string[];
}

/**
 * Tool permission entry
 */
export interface ToolPermission {
  tool_id: string;
  enabled: boolean;
  scopes?: string[];
}
