import request from '@/axios'
import { REQUEST_BASE } from '@/constants'
import { userSearch, userLevelSearch, userLevelData, userData } from './types'
export const getUserLevel = (params: userLevelSearch): Promise<IResponse> => {
  return request.get({ url: `${REQUEST_BASE}/user_level`, params })
}
export const addUserLevel = (data: userLevelData): Promise<IResponse> => {
  return request.post({ url: `${REQUEST_BASE}/user_level`, data })
}
export const delUserLevel = (id: number): Promise<IResponse> => {
  return request.delete({ url: `${REQUEST_BASE}/user_level/${id}` })
}
export const putUserLevelStatus = (data: { id: number; status: number }): Promise<IResponse> => {
  return request.put({ url: `${REQUEST_BASE}/user_level/set_status/${data.id}/${data.status}` })
}

export const putUserLevel = (data: userLevelData): Promise<IResponse> => {
  return request.put({ url: `${REQUEST_BASE}/user_level/${data.id}`, data })
}
/**
 * 清除用户的等级信息
 *
 * 此函数通过发送DELETE请求来清除指定用户等级信息它需要一个用户ID作为参数，
 * 并返回一个Promise对象，该对象解析为IResponse类型这可以用于处理请求的成功或失败
 *
 * @param id 用户ID，用于指定需要清除等级信息的用户
 * @returns 返回一个Promise对象，包含请求的结果，类型为IResponse
 */
export const clearUserLevel = (id: number): Promise<IResponse> => {
  return request.delete({ url: `${REQUEST_BASE}/user/delLevel/${id}` })
}

export const getUserList = (params: userSearch): Promise<IResponse> => {
  return request.get({ url: `${REQUEST_BASE}/user`, params })
}
export const getUserDetail = (id: number): Promise<IResponse> => {
  return request.get({ url: `${REQUEST_BASE}/user/${id}` })
}
export const addUserData = (data: userData): Promise<IResponse> => {
  return request.post({ url: `${REQUEST_BASE}/user`, data })
}
export const delUserData = (id: number): Promise<IResponse> => {
  return request.delete({ url: `${REQUEST_BASE}/user/${id}` })
}
export const putUserData = (data: userData): Promise<IResponse> => {
  return request.put({
    url: `${REQUEST_BASE}/user/${data.uid}`,
    data
  })
}
export const levelTaskBase = (): Promise<IResponse> => {
  return request.get({ url: `${REQUEST_BASE}/user_level/task_base` })
}
export const getUserGroup = (params: { page: number; limit: number }): Promise<IResponse> => {
  return request.get({ url: `${REQUEST_BASE}/user_group`, params })
}
export const addUserGroup = (group_name: string): Promise<IResponse> => {
  return request.post({ url: `${REQUEST_BASE}/user_group`, data: { group_name } })
}
export const delUserGroup = (id: number): Promise<IResponse> => {
  return request.delete({ url: `${REQUEST_BASE}/user_group/${id}` })
}
export const putUserGroup = (data: { id: number; group_name: string }): Promise<IResponse> => {
  return request.put({
    url: `${REQUEST_BASE}/user_group/${data.id}`,
    data: { group_name: data.group_name }
  })
}
export const setGroup = (data: {
  group_id: number
  uids: string
  all: number
  where: any
}): Promise<IResponse> => {
  return request.put({
    url: `${REQUEST_BASE}/user/setGroup`,
    data
  })
}
/**
 * 用户附加信息【余额流水】
 * @param params
 * @param id
 * @returns
 */
export const getBalanceLog = (
  params: { pm?: number; type?: string; page: number; limit: number },
  id: number
): Promise<IResponse> => {
  return request.get({ url: `${REQUEST_BASE}/user/detail/balance_log/${id}`, params })
}
/**
 * 用户附加信息【推荐人列表】
 * @param params
 * @param id
 * @returns
 */
export const getSpreadList = (params: { page: number; limit: number }, id): Promise<IResponse> => {
  return request.get({ url: `${REQUEST_BASE}/user/detail/spread/${id}`, params })
}
/**
 * 用户附加信息【佣金流水】
 * @param params
 * @param id
 * @returns
 */
export const getBrokerageLog = (
  params: { page: number; limit: number; pm?: number; type?: string },
  id
): Promise<IResponse> => {
  return request.get({ url: `${REQUEST_BASE}/user/detail/brokerage_log/${id}`, params })
}
/**
 * 用户附加信息【其他代币流水】
 * @param params
 * @param id
 * @returns
 */
export const getBillLog = (params: { page: number; limit: number }, id): Promise<IResponse> => {
  return request.get({ url: `${REQUEST_BASE}/user/detail/bill_log/${id}`, params })
}
export const putGiveLevel = (data: { level_id: number; id: number }): Promise<IResponse> => {
  return request.post({
    url: `${REQUEST_BASE}/user/giveLevel/${data.id}`,
    data: { level_id: data.level_id }
  })
}
export const updateAccount = (
  data: { money_type: string; pm: number; num: number; mark: string },
  id
): Promise<IResponse> => {
  return request.put({
    url: `${REQUEST_BASE}/user/updateAccount/${id}`,
    data
  })
}
