import { request } from '@/http/axios'
import {
  BindQyUserCommand,
  BindWxMpUserCommand,
  GetTokenParams,
  LoginData,
  LogoutResponse,
  SmsSendResponse,
  TokenResponse,
  VerifySmsParams,
  WechatQrCodeParams
} from './type'
import { ab98UserDTO } from '../shop/type'

/** 获取临时令牌 */
export function getTokenApi(appName: string) {
  return request<ApiResponseData<TokenResponse>>({
    url: '/wx/login/getToken',
    method: 'get',
    params: { appName }
  })
}

/** 获取微信登录二维码 */
export function getWechatQrCodeApi(token: string) {
  return request<ApiResponseData<string>>({
    url: '/wx/login/wechat/qrcode',
    method: 'get',
    params: { token }
  })
}

/** 发送短信验证码 */
export function sendSmsApi(token: string, tel: string) {
  return request<ApiResponseData<SmsSendResponse>>({
    url: '/wx/login/sendSms',
    method: 'post',
    params: { token, tel }
  })
}

/** 验证短信验证码 */
export function verifySmsApi(params: VerifySmsParams) {
  return request<ApiResponseData<LoginData>>({
    url: '/wx/login/verifySms',
    method: 'post',
    params
  })
}

/** 用户退出登录 */
export function logoutApi(token: string) {
  return request<ApiResponseData<LogoutResponse>>({
    url: '/wx/login/logout',
    method: 'post',
    params: { token }
  })
}

/** ab98Token登录 */
export function tokenLogin(token: string, userid: string, openid: string) {
  return request<ApiResponseData<LoginData>>({
    url: '/wx/login/tokenLogin',
    method: 'get',
    params: { token, userid, openid }
  })
}

export function bindQyUserApi(data: BindQyUserCommand) {
  return request<ApiResponseData<ab98UserDTO>>({
    url: '/wx/login/bindQyUser',
    method: 'post',
    data
  })
}

export function bindWxMpUser(data: BindWxMpUserCommand) {
  return request<ApiResponseData<string>>({
    url: '/wx/login/bindWxMpUser',
    method: 'post',
    data
  })
}