import { defHttp } from '/@/utils/http/axios'

import { ErrorMessageMode } from '/@/utils/http/axios/types'
import { BasicPageParams } from '/@/api/model/baseModel'
enum Api {
  GetManagerList = '/backstage/manager/list',
  GetManagerInfo = '/backstage/manager',
  SaveManagerStatus = '/backstage/manager/enable',
  GetGroupList = '/backstage/group/list',
  DeleteGroup = '/backstage/group/delete',
  AddGroup = '/backstage/group/add',
  UpdateGroup = 'backstage/group/update',
  UpdateBackStageStaff = '/backstage/manager/update'
}
import {
  ManagerListGetResultModel,
  ManagerInfoGetResultModel,
  AddPermParams,
  PermGroupListResultModel,
  UpdatePermParams,
  UpdateBackstageStaffParmas
} from './model/managerModel'
/**
 * @description 获取后台用户列表
 */
export function getManagerList(params: BasicPageParams) {
  return defHttp.get<ManagerListGetResultModel>({
    url: Api.GetManagerList,
    params
  })
}

/**
 * @description 获取后台用户详情
 */
export function getManagerInfoById(params: { id: string }) {
  return defHttp.get<ManagerInfoGetResultModel>({
    url: Api.GetManagerInfo,
    params
  })
}

/**
 * @description 后台用户启用/禁用
 */
export function toggleManagerStatus(params: { id: string; canLogin: 0 | 1 }, mode: ErrorMessageMode = 'modal') {
  return defHttp.post(
    {
      url: Api.SaveManagerStatus,
      params
    },
    {
      errorMessageMode: mode
    }
  )
}

/** 获取权限列表 */
export function getPermGroupList(params: BasicPageParams) {
  return defHttp.get<PermGroupListResultModel>({
    url: Api.GetGroupList,
    params
  })
}

/** 删除权限 */
export function deletePermGroup(id: string) {
  return defHttp.delete({
    url: Api.DeleteGroup,
    params: { id }
  })
}

/** 新增权限组 */
export function addPermGroup(params: AddPermParams) {
  return defHttp.post({
    url: Api.AddGroup,
    params
  })
}

/** 编辑权限组 */
export function updatePermGroup(params: UpdatePermParams) {
  return defHttp.post({
    url: Api.UpdateGroup,
    params
  })
}

/** 编辑后台用户 */
export function updateBackStageStaff(params: UpdateBackstageStaffParmas) {
  return defHttp.post({
    url: Api.UpdateBackStageStaff,
    params
  })
}
