import type { KnowledgeConfig } from './components/Knowledge/types'
import type { Variable } from './components/VariableList/types'
import type { ToolOption } from './components/ToolList/types'
import type { ChatItem } from '@/components/Chat/types'
import type { GraphRef } from '@/views/Workflow/types';
import type { ApiKey } from '@/views/ApiKeyManagement/types'

export interface ModelConfig {
  label?: string;
  default_model_config_id?: string;
  temperature: number;
  max_tokens: number;
  top_p: number;
  frequency_penalty: number;
  presence_penalty: number;
  n: number;
  stop?: string;
}
export interface MemoryConfig {
  enabled: boolean;
  memory_content?: string;
  max_history?: number | string;
}

export interface Config extends MultiAgentConfig {
  id: string;
  app_id: string;
  system_prompt: string;
  default_model_config_id?: string;
  model_parameters: ModelConfig;
  knowledge_retrieval: KnowledgeConfig | null;
  memory?: MemoryConfig;
  variables: Variable[];
  tools: ToolOption[];
  is_active: boolean;
  created_at: number;
  updated_at: number;
}
export interface MultiAgentConfig {
  id: string;
  app_id: string;
  default_model_config_id?: string;
  model_parameters: ModelConfig;
  sub_agents?: SubAgentItem[];
  routing_rules: null;
  orchestration_mode: 'supervisor' | 'collaboration';
  execution_config: {
    sub_agent_execution_mode: 'sequential' | 'parallel';
  };
  aggregation_strategy: 'merge' | 'vote' | 'priority'
}

// 创建表单数据类型
export interface ApplicationModalData {
  name: string;
  type: string;
  icon: string;
}

// 定义组件暴露的方法接口
export interface AgentRef {
  handleSave: (flag?: boolean) => Promise<unknown>;
}
export interface ClusterRef {
  handleSave: (flag?: boolean) => Promise<unknown>;
}
export interface WorkflowRef {
  handleSave: (flag?: boolean) => Promise<unknown>;
  handleRun: () => void;
  graphRef: GraphRef;
  addVariable: () => void;
}
export interface ApplicationModalRef {
  handleOpen: (application?: Config) => void;
}
export type Source = 'chat' | 'model' | 'multi_agent'
export interface ModelConfigModalRef {
  handleOpen: (source: Source, model?: any) => void;
}
export interface ModelConfigModalData {
  model: string;
  [key: string]: string;
}
export interface AiPromptModalRef {
  handleOpen: () => void;
}
export interface ChatData {
  label?: string;
  model_config_id?: string;
  model_parameters?: ModelConfig;
  list?: ChatItem[];
  conversation_id?: string | null;
}
export interface Release {
  id: string;
  app_id: string;
  version: string;
  release_notes: string;
  name: string;
  description?: string;
  icon: string;
  icon_type?: string;
  type: string;
  visibility: string;
  config: Config;
  default_model_config_id?: string;
  published_by?: string;
  published_at: number;
  publisher_name?: string;
  is_active?: boolean;
  created_at?: number;
  updated_at?: number;
  status?: string;
  version_name?: string;
  tagKey: 'current' | 'rolledBack' | 'history';
}
export interface ReleaseModalRef {
  handleOpen: () => void;
}
export interface ReleaseShareModalRef {
  handleOpen: () => void;
}
export interface CopyModalRef {
  handleOpen: () => void;
}
export interface SubAgentItem {
  agent_id: string;
  name: string;
  role: string;
  capabilities: string[];
  is_active?: boolean;
}
export interface SubAgentModalRef {
  handleOpen: (agent?: SubAgentItem) => void;
}
export interface ApiKeyModalRef {
  handleOpen: () => void;
}
export interface ApiKeyConfigModalRef {
  handleOpen: (apiKey: ApiKey) => void;
}
export interface AiPromptVariableModalRef {
  handleOpen: () => void;
}

export interface AiPromptForm {
  model_id?: string;
  message?: string;
  current_prompt?: string;
}
export interface ChatVariableConfigModalRef {
  handleOpen: (values: Variable[]) => void;
}