import { request } from '@/utils/request'
import type {
  BaseResponse,
  GetOpenIdResponse,
  LoginRequest,
  LoginResponse,
  UserInfo,
  UpdateUserInfoRequest,
  InviteUserItem,
  SpendHistoryItem,
  PayInfoList,
  GetInviteCodeResponse,
  RefundInfoList,
} from './type'

/** 获取用户openId */
export const getOpenIdAPI = (code: string) =>
  request.post<BaseResponse<GetOpenIdResponse>>('/sys/getOpenId', { code })

/** 用户登录 */
export const loginAPI = (data: LoginRequest) =>
  request.post<BaseResponse<LoginResponse>>('/base/mobileLogin', data)

/** 获取用户信息 */
export const getUserInfoAPI = (id: string) =>
  request.get<BaseResponse<UserInfo>>(`/user/info/${id}`)

/** 更新用户信息 */
export const updateUserInfoAPI = (data: UpdateUserInfoRequest) =>
  request.post<BaseResponse>('/user/update', data)

/**
 * banner图片
 */
export const getBannerImage = () => request.get<BaseResponse>('/attachment/getBannerImage')

/** 获取我邀请的用户列表 */
export const getMyInviteListAPI = () =>
  request.get<BaseResponse<InviteUserItem[]>>('/user/myInvite')

/** 获取用户消费明细 */
export const getUserSpendHistoryAPI = (id: string) =>
  request.get<BaseResponse<SpendHistoryItem[]>>(`/user/spendHistory/${id}`)

export const getUserPayInfoAPI = () => request.get<BaseResponse<PayInfoList[]>>(`/pay/payInfo`)

/** 获取用户退款记录 */
export const getUserRefundInfoAPI = () =>
  request.get<BaseResponse<RefundInfoList[]>>('/pay/refundInfo')

/** 撤销退款申请 */
export const cancelRefundAPI = (id: string) => request.get<BaseResponse>(`/pay/cancelRefund/${id}`)

/** 退出登录 */
export const logoutAPI = () => request.get<BaseResponse>('/sys/logout')

/** 获取邀请码 */
export const getInviteCodeAPI = () =>
  request.get<BaseResponse<GetInviteCodeResponse>>('/sys/getInviteCode')

/** 绑定邀请人 */
export const bindInviterAPI = (code: string) => {
  return request.get(`/sys/bindInviteUser/${code}`)
}
