import {
  bluebookAiAgent,
} from '@/xiaolanbenlib/api/index'
import request from '@/xiaolanbenlib/module/axios.js'
import { TAgentDetail, TComponentItem, TEditAgentCharacter, TAgentContactCard, TAgentShared, TAgent, TAgentRequiredData } from '@/types/agent'






// 获取我的智能体详细信息
// 供编辑页使用，预览页使用智能体信息接口获取
export const getMyAgent = (agentId: string) => {
  return request.get<TAgentDetail>(`${bluebookAiAgent}api/v1/my/agent/${agentId}`)
}

// 获取创建智能体时的默认填充内容项
export const getNewAgentInfo = () => {
  return request.get<Partial<TAgentDetail>>(`${bluebookAiAgent}api/v1/my/new/agent/info`)
}
// 创建新智能体
export const createNewAgent = (data: Omit<TAgentRequiredData, 'agentId'>) => {
  return request.post<TAgentDetail>(`${bluebookAiAgent}api/v1/my/agent/create`, data)
}
// 编辑智能体
export const editAgent = (data: TAgentRequiredData) => {
  return request.put(`${bluebookAiAgent}api/v1/my/agent/${data.agentId}`, data)
}

// 设置当前我的默认智能体
export const setDefaultAgent = (agentId: string) => {
  return request.put(`${bluebookAiAgent}api/v1/my/agent/${agentId}/default`)
}

// 编辑智能体--微官网组件
export const editAgentWebsite = (agentId: string, data: {components: TComponentItem[]}) => {
  return request.put(`${bluebookAiAgent}api/v1/my/agent/${agentId}/website`, data)
}





// 我的智能体列表
export const getAgents = () =>  {
  return request.get<TAgent[]>(`${bluebookAiAgent}api/v1/my/agents`)
}
// 删除智能体--仅允许删除个人智能体
export const deleteAgent = (agentId: string) => {
  return request.delete(`${bluebookAiAgent}api/v1/my/agent/${agentId}`)
}


// 访问某个智能体，允许不登录状态下访问
export const getAgent = (agentId: string, shareKey?: string) =>  {
  return request.get<TAgentDetail>(`${bluebookAiAgent}api/v1/agent/${agentId}`, {
    params: {shareKey}
  })
}

// 上报访客日志--间隔 N 秒调用一次
export const postVisitorLog = (data: {
  agentId: string,
  loginId: string,
  shareKey?: string,
}) => {
  return request.post<TAgentDetail>(`${bluebookAiAgent}api/v1/agent/visitor/log`, data)
}

// 文本润色
export const textPolishing = (data: {
  content: string
  type: 'personality'|'greeting' // 人设/开场白
}) => {
  return request.post<{content: string}>(`${bluebookAiAgent}api/v1/my/agent/textPolishing`, data)
}

// 获取智能体的分享信息--仅登录才能分享
export const getAgentShareInfo = (agentId: string) => {
  return request.get<TAgentShared>(`${bluebookAiAgent}api/v1/agent/${agentId}/shareInfo`)
}

// 批量获取智能体信息，用于微官网组件 -- 允许未登录用户直接访问
export const getAgentBatch = (agentIds: string) => {
  return request.get<TAgent[]>(`${bluebookAiAgent}api/v1/agent/batch`, {
    params: {agentIds}
  })
}

// 获取指定企业的同事智能体--用于官网信息中智能体推荐部份--包含自己的智能体
export const getEntAgentPartners = (params: {
  entId: number|string,
  startId?: string
  pageSize: number
}) => {
  return request.get<TAgent[]>(`${bluebookAiAgent}api/v1/my/ent/${params.entId}/agent/partners`, {
    params
  })
}





// ============ deprecated ===========

// 编辑智能体--设置形象ID
// deprecated
// export const editAgentAvatar = (agentId: string, avatarId: string|number, enabledChatBg:boolean) => {
//   return request.put(`${bluebookAiAgent}api/v1/my/agent/${agentId}/avatar`, {
//     avatarId,
//     enabledChatBg,
//   })
// }


// 编辑智能体--名片部份内容
// address (string, optional): 地址，长度最多250 ,
// email (string, optional): 邮箱，长度最多50 ,
// entName (string, optional): 企业名称，长度最多100，如果是个人版允许编辑、企业版可以原值传入即可 ,
// mobile (string, optional): 手机号 ,
// name (string, optional): 智能体名称--名片的姓名；长度最多20 ,
// position (string, optional): 职位，长度最多30 ,
// qrCodeUrl (string, optional): 二维码地址，长度最多250

// deprecated
export const editAgentCard = (agentId: string, data: TAgentContactCard) => {
  return request.put<any, any>(`${bluebookAiAgent}api/v1/my/agent/${agentId}/card`, data)
}

// 编辑智能体--声音、人设、开场白、问题引导、知识库
// deprecated
export const editAgentCharacter = (agentId: string, data: TEditAgentCharacter) => {
  return request.put(`${bluebookAiAgent}api/v1/my/agent/${agentId}/character`, data)
}
