import { ContentTypeEnum } from '@/enums/httpEnum'
import { http } from '@/utils/http/axios'

export interface BasicResponseModel<T = any> {
  code: number
  message: string
  result: T
}

export interface BasicPageParams {
  pageNumber: number
  pageSize: number
  total: number
}

/**
 * 获取验证码主键
 * @param type
 * @returns
 */
export function getCaptchaToken(type: 'math' | 'char') {
  return http.request({
    url: `/captcha/captchatoken`,
    method: 'get',
    params: { type },
  })
}

/**
 * 获取验证码
 */
export function getCaptcha(codeToken: string) {
  return http.request({
    url: `/captcha/captchaImage`,
    method: 'get',
    params: { codeToken },
    responseType: 'arraybuffer',
  })
}

/**
 * 登录
 * @param params
 * @returns
 */
export function login_new(params) {
  return http.request({
    url: '/backstage/adminlogin',
    method: 'POST',
    params,
    headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
  })
}

/**
 * 获取用户信息
 * @param logintoken
 * @returns
 */
export function getInformation() {
  return http.request({
    url: '/static/admin/web/shoInformation',
    method: 'get',
  })
}

/**
 * 刷新token
 * @returns
 */
export function refreshToken() {
  return http.request({
    url: '/oauthweb/token',
    method: 'POST',
  })
}

/**
 * 获取配置（aside是否显示某个模块）
 * @returns
 */
export async function getConfig() {
  return await http.request({
    url: `/ocr/ocrConfiguration/getConfiguration`,
    method: 'get',
  })
}

/** *******************************分割线 */

/**
 * @description: 获取用户信息
 */
export function getUserInfo() {
  return http.request({
    url: '/admin_info',
    method: 'get',
  })
}

/**
 * @description: 用户登录
 */
export function login(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/login',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    },
  )
}

/**
 * @description: 用户登出
 */
export function logout(params) {
  return http.request({
    url: '/login/logout',
    method: 'POST',
    params,
  })
}
