import { defHttp } from '/@/utils/http/axios'
import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel'

import { ErrorMessageMode } from '/#/axios'

enum Api {
  Login = '/api/auth/login',
  Logout = '/api/users/logout',
  GetUserInfo = '/api/users/info',
  GetPermCode = '/getPermCode',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    },
  )
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' })
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode })
}

export function doLogout() {
  return defHttp.delete({ url: Api.Logout })
}
/**
 * @description:权限数据
 */
export function getPermissions() {
  return defHttp.get(
    {
      url: '/api/permissions',
    },
    {
      errorMessageMode: 'none',
    },
  )
}
/**
 * @description:角色列表
 */
export function getRoles(params, mode: ErrorMessageMode = 'modal') {
  return defHttp.get(
    {
      url: '/api/admin-roles',
      params,
    },
    {
      errorMessageMode: mode,
    },
  )
}
/**
 * @description:添加角色
 */
export function addRoles(data, mode: ErrorMessageMode = 'modal') {
  return defHttp.post(
    {
      url: '/api/admin-roles',
      data,
    },
    {
      errorMessageMode: mode,
    },
  )
}
/**
 * @description:修改角色
 */
export function editRoles(id: string, data, mode: ErrorMessageMode = 'modal') {
  return defHttp.put(
    {
      url: `/api/admin-roles/${id}`,
      data,
    },
    {
      errorMessageMode: mode,
    },
  )
}
/**
 * @description:获取角色详情
 */
export function getRolesInfo(id, mode: ErrorMessageMode = 'modal') {
  return defHttp.get(
    {
      url: `/api/admin-roles/${id} `,
    },
    {
      errorMessageMode: mode,
    },
  )
}
/**
 * @description:删除角色
 */
export function deleteRoles(id: string, mode: ErrorMessageMode = 'modal') {
  return defHttp.delete(
    {
      url: `/api/admin-roles/${id}`,
    },
    {
      errorMessageMode: mode,
    },
  )
}
