import request from '@/utils/request'

// 获取会话列表（分页）
export function getChatSessionList(query) {
  return request({
    url: '/crm/customer/chat/chatSession/list',
    method: 'get',
    params: query
  })
}

// 创建新会话
export function createChatSession(data) {
  return request({
    url: '/crm/customer/chat/chatSession',
    method: 'post',
    data: data
  })
}

// 更新会话标题
export function updateChatSessionTitle(data) {
  return request({
    url: '/crm/customer/chat/chatSession/title',
    method: 'put',
    data: data
  })
}

// 更新会话关联客户
export function updateChatSessionCustomer(sessionId, customerId) {
  return request({
    url: '/crm/customer/chat/chatSession/customer',
    method: 'put',
    data: { sessionId, customerId }
  })
}

// 删除会话
export function deleteChatSession(sessionId) {
  return request({
    url: '/crm/customer/chat/chatSession/' + sessionId,
    method: 'delete'
  })
}
// 置顶/取消置顶会话
export function pinChatSession(sessionId, isPinned) {
    return request({
        url: '/crm/customer/chat/chatSession/pin',
        method: 'put',
        data: { sessionId, isPinned }
    })
}
//获取AI回复
export function getAiReply(data) {
    return request({
        url: '/crm/customer/chat/chatSession/polishingScript',
        method: 'post',
        data: data
    })
}

// 获取消息列表（分页，带时间游标）
export function getChatMessageList(query) {
  return request({
    url: '/crm/customer/chat/chatMsg/list',
    method: 'get',
    params: query
  })
}

// 批量保存消息
export function batchSaveMessages(data) {
  return request({
    url: '/crm/customer/chat/chatMsg/batch',
    method: 'post',
    data: data
  })
}

// 单条消息保存
export function saveChatMessage(data) {
  return request({
    url: '/crm/customer/chat/chatMsg',
    method: 'post',
    data: data
  })
}

// 更新消息
export function updateChatMessage(data) {
  return request({
    url: '/crm/customer/chat/chatMsg',
    method: 'put',
    data: data
  })
}

// 删除消息
export function deleteChatMessage(msgId) {
  return request({
    url: '/crm/customer/chat/chatMsg/' + msgId,
    method: 'delete'
  })
}

// 获取会话详情
export function getChatSessionDetail(sessionId) {
  return request({
    url: '/crm/customer/chat/chatMsg/' + sessionId,
    method: 'get'
  })
}

