import http from '@/service'
import type { sendParams } from '@/types/login'

export function getSmsCode(phone: string) {
  return http.get(`/admin/mobile/${phone}`)
}

export function loginBySms(mobile: string, code: string) {
  return http.post(`auth/mobile/token/sms?code=${code}&mobile=SMS@${mobile}&grant_type=mobile`)
}

export function logoutApi() {
  return http.delete(`auth/token/logout`)
}

export function loginByPassword(mobile: string, password: string) {
  const grant_type = 'password'
  const passwordStr = encodeURIComponent(password)
  return http.post(
    `/auth/oauth/token?grant_type=${grant_type}&username=${mobile}&password=${passwordStr}&w1=${passwordStr}&scope=server`,
    {},
    {
      header: {
        isToken: false,
        'TENANT-ID': '1'
      }
    }
  )
}

export function getUserInfoByCode(wxCode: string, avatar: string) {
  return http.get(`admin/api/getUserInfoByCode?code=${wxCode}&avatar=${avatar}`)
}

export function changeEnt(sendParams: sendParams) {
  return http.post(
    `auth/mobile/token/smsForChangeEnt?drugEntId=${sendParams.code}&mobile=SMS@${sendParams.phone}&grant_type=changeEnt`
  )
}

export function getMobileUpdApi(mobile: string | number) {
  return http.get(`/admin/mobile/upd/${mobile}`)
}

export function postUserUpdApi(data: any) {
  return http.post(`/admin/user/upd`, data)
}
