import { api } from '@/api/index'
import type { ResultDomain, PageRequest } from '@/types'
import type { TbAgent } from '@/types/ai'

/**
 * @description    智能体管理接口
 * @filename    agent.ts
 * @author    yslg
 * @copyright xyzh
 * @since 2025-12-19
 */
export const agentAPI = {
    baseUrl: '/urban-lifeline/ai/agent',

    /**
     * 创建智能体
     * @param agent 智能体信息
     */
    async createAgent(agent: TbAgent): Promise<ResultDomain<TbAgent>> {
        const response = await api.post<TbAgent>(`${this.baseUrl}`, agent)
        return response.data
    },

    /**
     * 更新智能体
     * @param agent 智能体信息
     */
    async updateAgent(agent: TbAgent): Promise<ResultDomain<TbAgent>> {
        const response = await api.put<TbAgent>(`${this.baseUrl}`, agent)
        return response.data
    },

    /**
     * 删除智能体
     * @param agentId 智能体ID
     */
    async deleteAgent(agentId: string): Promise<ResultDomain<TbAgent>> {
        const response = await api.delete<TbAgent>(`${this.baseUrl}/${agentId}`)
        return response.data
    },

    /**
     * 获取智能体详情
     * @param agentId 智能体ID
     */
    async getAgent(agentId: string): Promise<ResultDomain<TbAgent>> {
        const response = await api.get<TbAgent>(`${this.baseUrl}/${agentId}`)
        return response.data
    },

    /**
     * 分页查询智能体
     * @param pageRequest 分页请求参数
     */
    async getAgentPage(pageRequest: PageRequest<TbAgent>): Promise<ResultDomain<TbAgent>> {
        const response = await api.post<TbAgent>(`${this.baseUrl}/page`, pageRequest)
        return response.data
    },

    /**
     * 获取智能体列表
     * @param filter 筛选条件
     */
    async getAgentList(filter?: TbAgent): Promise<ResultDomain<TbAgent>> {
        const response = await api.get<TbAgent>(`${this.baseUrl}/list`, { params: filter })
        return response.data
    }
}