import type { AIAgent } from '../types'
import { getRecord, updateRecord } from './common'

// 重新导出类型，供其他模块使用
export type { AIAgent }

export const getAgentDetail = async (name: string, pageType: string): Promise<AIAgent> => {
  try {
    const result = await getRecord(pageType, name)
    
    if (!result.success) {
      throw new Error(result.message || '获取AI Agent详情失败')
    }
    
    return result.data
  } catch (error: any) {
    throw new Error(error.message || '获取AI Agent详情失败')
  }
}

export const updateAgentApi = async (name: string, data: Partial<AIAgent>, pageType: string): Promise<AIAgent> => {
  try {
    const result = await updateRecord(pageType, name, data)
    
    if (!result.success) {
      throw new Error(result.message || '更新AI Agent失败')
    }
    
    return result.data
  } catch (error: any) {
    console.error("Error in updateAgentApi:", error)
    throw new Error(error.message || '更新AI Agent失败')
  }
}