import api from './api';
import request from '@/utils/request';
import type {
  IAgentCreateRequestBody, IAgentPaginationParams,
  IAgentSetDSLRequestBody, IAgentSettingRequestBody
} from '@/interfaces/request/agent';

/**
 * 智能体服务
 */
const agentService = {
  /**
   * 获取团队下的Canvas列表
   */
  listCanvas: (params?: IAgentPaginationParams) => {
    return request.get(api.listCanvas, { params });
  },
  /**
   * 获取团队下的Canvas列表
   */
  teamlistCanvas: (params?: IAgentPaginationParams) => {
    return request.get(api.listTeamCanvas, { params });
  },
  /**
   * 获取系统模板列表
   */
  listTemplates: () => {
    return request.get(api.listTemplates);
  },
  /**
   * 新建或更新 Canvas（Agent/Dataflow）
   */
  setCanvas: (body: IAgentCreateRequestBody) => {
    return request.post(api.setCanvas, body);
  },
  /**
   * 获取智能体详情
   * @param canvas_id Canvas ID
   */
  getCanvas: (canvas_id: string) => {
    return request.get(`${api.getCanvas}/${canvas_id}`);
  },
  /**
   * 获取智能体实时运行状态
   * @param canvas_id Canvas ID
   */
  getCanvasSSE: (canvas_id: string) => {
    return request.get(`${api.getCanvasSSE}/${canvas_id}`);
  },
  /**
   * 删除 Canvas（Agent/Dataflow）
   * @param canvas_ids ID列表
   */
  removeCanvas: (canvas_ids: string[]) => {
    return request.post(api.removeCanvas, { canvas_ids });
  },

  /**
   * 获取 Canvas 设置
   */
  settingAgent: (data: Partial<IAgentSettingRequestBody>) => {
    return request.post(api.settingCanvas, data);
  },
  /**
   * 设置智能体DSL
   */
  setAgentDSL: (data: Partial<IAgentSetDSLRequestBody>) => {
    return request.post(api.setCanvas, data);
  },
  /**
   * 运行 Canvas（同步接口）
   */
  runCanvas: (body: Record<string, any>) => {
    return request.post(api.runCanvas, body);
  },
  /**
   * 数据库连接测试
   */
  testDbConnect: (body: Record<string, any>) => {
    return request.post(api.testDbConnect, body);
  },
  /**
   * 获取输入元素（Begin Inputs）
   */
  getInputElements: (params?: Record<string, any>) => {
    return request.get(api.getInputElements, { params });
  },
  /**
   * 调试运行（Debug 单步）
   */
  debug: (body: Record<string, any>) => {
    return request.post(api.debug, body);
  },
  /**
   * 上传与 Canvas 相关的文件
   */
  uploadCanvasFile: (formData: FormData) => {
    return request.post(api.uploadCanvasFile, formData);
  },
  /**
   * 获取 Canvas 运行追踪
   */
  trace: (params?: Record<string, any>) => {
    return request.get(api.trace, { params });
  },
  /**
   * 获取智能体版本详情
   * @param version_id 版本ID
   */
  getVersion: (version_id: string) => {
    return request.get(`${api.getVersion}/${version_id}`);
  },
  /**
   * 获取智能体版本列表
   * @param canvas_id Canvas ID
   */
  getAgentVersionList: (canvas_id: string) => {
    return request.get(`${api.getListVersion}/${canvas_id}`);
  },
  /**
   * 获取智能体 Prompts
   * {Promise<{task_analysis: string,citation_guidelines: string, plan_generation: string, reflection: string}>}
   */
  getCanvasPrompt: () => {
    return request.get(api.prompts);
  },
};

export default agentService;