import type { AxiosResponse } from 'axios'
import type {
  Result,
  PageInfo,
  HeaiMessageTypeInfo,
  HeaiMessageInfo,
  HeaiMessageQueryInfo,
  HeaiMessageFlag
} from '@cacp/ui'
import request from '@/utils/request'

const contextPath = '/heai'

export async function getMessageTypeList(): Promise<Result<HeaiMessageTypeInfo[]>> {
  const res: AxiosResponse<Result<HeaiMessageTypeInfo[]>> = await request.get(
    `${contextPath}/get-message-type-list`
  )
  return res.data
}
export async function insertMessageType(info: HeaiMessageTypeInfo): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(
    `${contextPath}/insert-message-type`,
    info
  )
  return res.data
}

export async function deleteMessageType(typeCode: string): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(
    `${contextPath}/delete-message-type?typeCode=${typeCode}`
  )
  return res.data
}

export async function queryMessagePage(query: HeaiMessageQueryInfo): Promise<Result<PageInfo<HeaiMessageInfo>>> {
  const res: AxiosResponse<Result<PageInfo<HeaiMessageInfo>>> = await request.post(
    `${contextPath}/query-message-page`,
    query
  )
  return res.data
}

export async function updateMessage(info: {appMsgId: string, content: string}): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/update-message`, info)
  return res.data
}

export async function transferError(appMsgId: string): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/transfer-error`, null, {
    params: { appMsgId }
  })
  return res.data
}
export async function transferCmplete(appMsgId: string, type: boolean): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(
    `${contextPath}/transfer-complete`,
    null,
    {
      params: { appMsgId, type }
    }
  )
  return res.data
}

export async function transferWaiting(appMsgId: string, type: boolean, flag: HeaiMessageFlag): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(
    `${contextPath}/transfer-waiting`,
    null,
    {
      params: { appMsgId, type, flag }
    }
  )
  return res.data
}

export async function getRecieve(appMsgId: string, type: boolean, flag: HeaiMessageFlag): Promise<Result<HeaiMessageInfo>> {
  const res: AxiosResponse<Result<HeaiMessageInfo>> = await request.get(
    `${contextPath}/get-message`,
    {
      params: { appMsgId, type, flag }
    }
  )
  return res.data
  
}