import { request } from '../request';

/** get role list */
export function fetchGetRoleList(params?: Api.SystemManage.RoleSearchParams) {
  return request<Api.SystemManage.RoleList>({
    url: '/sys/role/page',
    method: 'get',
    params
  });
}

/**
 * get all roles
 *
 * these roles are all enabled
 */
export function fetchGetAllRoles() {
  return request<Api.SystemManage.AllRole[]>({
    url: '/systemManage/getAllRoles',
    method: 'get'
  });
}

/** get user list */
export function fetchGetUserList(params?: Api.SystemManage.UserSearchParams) {
  return request<Api.SystemManage.UserList>({
    url: '/sys/user/page',
    method: 'get',
    params
  });
}

/** get menu list */
export function fetchGetMenuList() {
  return request<Api.SystemManage.MenuList>({
    // url: '/systemManage/getMenuList/v2',
    url: '/sys/menu/table',
    method: 'get'
  });
}

/** get all pages */
export function fetchGetAllPages() {
  return request<string[]>({
    url: '/systemManage/getAllPages',
    method: 'get'
  });
}

/** get menu tree */
export function fetchGetMenuTree() {
  return request<Api.SystemManage.MenuTree[]>({
    url: '/systemManage/getMenuTree',
    method: 'get'
  });
}

/**
 * 新增菜单
 * @param data
 * @returns
 */
export function fetchAddMenu(data: Api.SystemManage.AddMenu) {
  return request({
    url: '/sys/menu',
    method: 'post',
    data
  });
}
/**
 * 编辑菜单
 * @param data
 * @returns
 */
export function fetchEditMenu(data: Api.SystemManage.AddMenu) {
  return request({
    url: '/sys/menu',
    method: 'put',
    data
  });
}

/**
 * 删除菜单
 * @param id
 * @returns
 */
export function fetchDelMenu(id: number) {
  return request({
    url: `/sys/menu/${id}`,
    method: 'delete'
  });
}

/**
 * 获取角色菜单列表
 * @param roleId
 * @returns
 */
export function fetchGetRoleMenuList(roleId: number) {
  return request<Api.SystemManage.RoleMenuList>({
    url: `/sys/role/info/${roleId}`,
    method: 'get'
  });
}
/**
 * 新增角色菜单列表
 * @param data
 * @returns
 */
export function fetchAddRoleMenu(data: Api.SystemManage.RoleMenuList) {
  return request({
    url: '/sys/role',
    method: 'post',
    data
  });
}
/**
 * 修改角色菜单列表
 * @param data
 * @returns
 */
export function fetchEditRoleMenu(data: Api.SystemManage.RoleMenuList) {
  return request({
    url: '/sys/role',
    method: 'put',
    data
  });
}
/**
 * 删除角色
 * @param roleId
 * @returns
 */

export function fetchDelRoleMenu(roleId: number) {
  return request({
    url: `/sys/role`,
    method: 'delete',
    data: [roleId]
  });
}

/**
 *  获取所有角色
 * @returns
 */
export function fetchGetRoleAllList() {
  return request<Api.SystemManage.RoleList>({
    url: '/sys/role/list',
    method: 'get'
  });
}

/**
 * 新增用户
 * @param data
 * @returns
 */
export function fetchAddUser(data: Api.SystemManage.UserModel) {
  return request({
    url: '/sys/user',
    method: 'post',
    data
  });
}

/**
 * 修改用户
 * @param data
 * @returns
 */ export function fetchEditUser(data: Api.SystemManage.UserModel) {
  return request({
    url: '/sys/user',
    method: 'put',
    data
  });
}

/**
 * 用户详情
 * @param id
 * @returns
 */
export function fetchDetaileUser(id: string) {
  return request<Api.SystemManage.UserModel>({
    url: `/sys/user/info/${id}`,
    method: 'get'
  });
}

/**
 * 删除用户
 * @param id
 * @returns
 */
export function fetchDeleteUser(id: number) {
  return request({
    url: `/sys/user`,
    method: 'delete',
    data: [id]
  });
}
