import request from './request';

export interface AgentConfig {
  id: string;
  name: string;
  nameEn: string;
  description: string;
  category: string;
  icon: string;
  enabled: boolean;
  systemPromptFile: string;
  userPromptTemplateFile: string;
  models: {
    [modelName: string]: {
      temperature: number;
      maxTokens: number;
      topP?: number;
    };
  };
  ragEnabled: boolean;
  requiresProject: boolean;
  outputFormat: 'text' | 'structured' | 'document';
  tags: string[];
}

export interface ApiResponse<T = any> {
  success: boolean;
  data?: T;
  message?: string;
  error?: string;
}

export const agentApi = {
  // 获取所有智能体列表
  getAll: async (): Promise<ApiResponse<AgentConfig[]>> => {
    return await request.get('/agents');
  },

  // 获取启用的智能体列表
  getEnabled: async (): Promise<ApiResponse<AgentConfig[]>> => {
    return await request.get('/agents/enabled');
  },

  // 获取单个智能体详情
  getById: async (id: string): Promise<ApiResponse<AgentConfig>> => {
    return await request.get(`/agents/${id}`);
  },

  // 根据分类获取智能体
  getByCategory: async (category: string): Promise<ApiResponse<AgentConfig[]>> => {
    return await request.get(`/agents/by-category?category=${encodeURIComponent(category)}`);
  },

  // 获取智能体的系统Prompt
  getSystemPrompt: async (id: string): Promise<ApiResponse<{ agentId: string; systemPrompt: string }>> => {
    return await request.get(`/agents/${id}/system-prompt`);
  },

  // 渲染用户Prompt
  renderPrompt: async (
    id: string,
    data: {
      projectBackground?: string;
      userInput: string;
      knowledgeBaseContext?: string;
    }
  ): Promise<ApiResponse<{ agentId: string; renderedPrompt: string }>> => {
    return await request.post(`/agents/${id}/render-prompt`, data);
  },
};

