import { usePost, stringify, useGet, usePut } from "@/.cool";
export type LoginData = {
  access_token: string;
  refresh_token: string;
}
export interface GetInfoResult {
  permissions: any[]
  roles: any[]
  sysRoles: any[]
  userInfo: any
}
export interface CONFIG_OPEN_CHILDREN_ALL {
  code: string
  name: string
  id: string
  content: string
  description: string
  type: number
  openFlag: boolean
}
export interface DICT_CHILDREN_ALL {
  code: string
  label: string
  value: string
}
export interface CONFIG_OPEN_VALUE {
  [key: string]: string
}
export interface DICT_DATA {
  'config:open:children-all': CONFIG_OPEN_CHILDREN_ALL[]
  'config:open:value': CONFIG_OPEN_VALUE
  'dict:children': {
    [key: string]: CONFIG_OPEN_VALUE
  }
  'dict:value:obj': {
    [key: string]: CONFIG_OPEN_VALUE
  }
  'dict:value': { [key: string]: CONFIG_OPEN_VALUE }
  'dict:code': { [key: string]: CONFIG_OPEN_VALUE }
  'dict:label': { [key: string]: CONFIG_OPEN_VALUE }
  'dict:children-all': { [key: string]: DICT_CHILDREN_ALL[] }
}
export function loginApi(params) {
  return usePost(`/oauth/token?${stringify(params)}`) as Promise<LoginData>
}
export function refreshTokenApi(refreshToken: string) {
  return usePost(
    `/oauth/token?grant_type=refresh_token&refresh_token=${refreshToken}`,
    null,
    { header: { Authorization: 'Basic ZW5kOmVuZA==' } }
  ) as Promise<LoginData>
}
export function sendSmsCode(params) {
  return usePost(`/verify/sms/code/send`, params) as Promise<string>
}
export function getUsersInfo() {
  return useGet(`/upms/users/info`) as Promise<GetInfoResult>
}
export function dictData() {
  return useGet(`/upms/dicts/data`) as Promise<DICT_DATA>
}
export function updateUserInfo(parameter: any) {
  return usePut(`/upms/users/change-info`, parameter) as Promise<any>
}
export function changeUserPwd(parameter: any) {
  return usePut(`/upms/users/change-pwd`, parameter) as Promise<any>
}
export function bindWechatOpenId(parameter: any) {
  return useGet(`/wechat/bind/small/program`, parameter) as Promise<any>
}
export function wechatLogin(parameter: any) {
  return useGet(`/wechat/quickly/login/oauth`, parameter) as Promise<any>
}
export function wechatPay(parameter: any) {
  return useGet(`/wechat/pay/jsapi`, parameter) as Promise<any>
}
export function wechatPayRequest(parameter: any) {
  return useGet(`/wechat/pay/request/payment`, parameter) as Promise<any>
}
export function exchangeCode(params) {
  return usePost(`/upms/users/exchange/code`, params) as Promise<any>
}
export function wechatPayQuery(parameter: any) {
  return useGet(`/wechat/pay/query/pay/result`, parameter) as Promise<any>
}
export function wechatPayCancel(parameter: any) {
  return usePut(`/wechat/pay/user/cancel/pay/${parameter.outTradeNo}`, parameter) as Promise<any>
}
export function quicklyRegister(params) {
  return usePost(`/upms/users/register/quickly`, params) as Promise<any>
}
export function selfRegister(params) {
  return usePost(`/upms/users/register/self`, params) as Promise<any>
}
export function getNoticeFlag() {
  return useGet(`/subject/notice-user/read/flag`) as Promise<any>
}