import request from '@/config/axios'

export interface UserVO {
  id: number
  parentId: number
  username: string
  password: string
  nickname: string
  remark: string
  email: string
  mobile: string
  countryCode: string
  invitationCode: string
  memberLevel: number
  creditScore: number
  userType: number
  sex: number
  avatar: string
  status: number
  loginIp: string
  loginDate: Date
}

export interface UserUpdateVO {
  id: number
  nickname: string
  remark: string
  email: string
  countryCode: string
  sex: number
  avatar: string
  status: number
  userType: number
}

// 查询会员信息列表
export const getUserPage = async (params) => {
  return await request.get({ url: `/admin/member/user/page`, params })
}

// 查询会员信息详情
export const getUser = async (id: number) => {
  return await request.get({ url: `/admin/member/user/get?id=` + id })
}

// 新增会员信息
export const createUser = async (data: UserVO) => {
  return await request.post({ url: `/admin/member/user/create`, data })
}

// 修改会员信息
export const updateUser = async (data: UserUpdateVO) => {
  return await request.put({ url: `/admin/member/user/update`, data })
}

// 删除会员信息
export const deleteUser = async (id: number) => {
  return await request.delete({ url: `/admin/member/user/delete?id=` + id })
}

// 导出会员信息 Excel
export const exportUser = async (params) => {
  return await request.download({ url: `/admin/member/user/export-excel`, params })
}

// 根据用户名查询会员信息
export const getUserByUsername = async (params) => {
  return await request.get({ url: `/admin/member/user/get/` + params })
}

// 查询用户任务完成情况
export const getUserTaskInfo = async (params) => {
  return await request.get({ url: `/admin/member/user/user-task-info`, params })
}

// 修改密码
export const updatePassword = async (data) => {
  return await request.put({ url: `/admin/member/user/update-password`, data })
}

// 修改用户等级
export const updateUserLevel = async (data) => {
  return await request.put({ url: `/admin/member/user/update-level`, data })
}

// 修改信誉分
export const updateCreditScore = async (data) => {
  return await request.put({ url: `/admin/member/user/update-credit-score`, data })
}

// 计算余额
export const calcUserBalance = async (params: any) => {
  return await request.get({ url: '/admin/member/user/calc-balance', params })
}
