import type {
  balanceLogParams,
  balanceLogResult,
  dashboardResult,
  profileDetail,
  profileParams,
} from '@/types/member'
import { request } from '@/utils/request'

export const getMemberProfileApi = () => {
  return request<profileDetail>({
    method: 'GET',
    url: 'shop/user/info',
  })
}

export const putMemberProfileApi = (data: profileParams) => {
  return request<profileDetail>({
    method: 'POST',
    url: 'shop/user/edit',
    data,
  })
}

export const getBalanceLogApi = (data: balanceLogParams) => {
  return request<balanceLogResult>({
    method: 'GET',
    url: 'shop/user/balanceLog',
    data,
  })
}

// 获取用户面板数据
export const getDashboardApi = () => {
  return request<dashboardResult>({
    method: 'GET',
    url: 'shop/user/dashboard',
  })
}

/**
 * 修改密码
 * @param data
 * @returns
 */
export const changePasswordApi = (data: { old_password: string; new_password: string }) => {
  return request<boolean>({
    method: 'POST',
    url: 'shop/user/changePassword',
    data,
  })
}

/**
 * 重置密码
 * @param data
 * @returns
 */
export const resetPasswordApi = (data: {
  phone: string
  sms_captcha_code: string
  new_password: string
}) => {
  return request({
    method: 'POST',
    url: 'shop/user/resetPassword',
    data,
  })
}

export const verificationApi = (data: { password: string; sms_captcha_code: string }) => {
  return request<{
    verificationToken: string
  }>({
    method: 'POST',
    url: 'shop/user/verification',
    data,
  })
}

export const changeBindApi = (data: {
  phone: string
  sms_captcha_code: string
  verification_token: string
}) => {
  return request({
    method: 'POST',
    url: 'shop/user/changeBind',
    data,
  })
}
