import request from '@/router/axios'
import { baseUrl } from '@/config/env'
import website from '@/const/website.js'
let basicAuth = 'Basic ' + window.btoa(website.formLoginClient)
export const loginByUsername = (username, password, code, redomStr) =>
  request({
    url: `/auth/oauth/token?randomStr=${website.passwordParam.randomStr}&code=&grant_type=password`,
    method: 'post',
    meta: {
      isToken: false,
      isSerialize: true
    },
    headers: {
      isToken: false,
      'TENANT-ID': '1',
      'Authorization': basicAuth
    },
    data: {
      username,
      password
    }
  })

export const getUserInfo = () =>
  request({
    url: baseUrl + '/user/getUserInfo',
    method: 'get'
  })

export const refeshToken = () =>
  request({
    url: baseUrl + '/user/refesh',
    method: 'post'
  })

  export const getMenu = (type = 0) =>
  request({
    url: '/admin/menu?size=9999&appCode=' + website.appCode,
    method: 'get',
    data: {
      type
    }
  })

export const getTopMenu = () =>
  request({
    url: baseUrl + '/user/getTopMenu',
    method: 'get'
  })

export const sendLogs = list =>
  request({
    url: baseUrl + '/user/logout',
    method: 'post',
    data: list
  })

export const logout = () =>
  request({
    url: '/auth/token/logout',
    meta: {
      isToken: false
    },
    method: 'delete'
  })
