import request from "@/utils/request";
import { AxiosPromise } from "axios";

/**
 * 获取角色分页数据
 *
 * @param queryParams
 */
export function getRolePage(
  queryParams?: any
): AxiosPromise<any> {
  return request({
    url: "/api/v1/sys/role/page",
    method: "post",
    data: queryParams,
  });
}

/**
 * 获取角色下拉数据
 *
 * @param queryParams
 */
export function getRoleOptions(
  queryParams?: any
): AxiosPromise<OptionType[]> {
  return request({
    url: "/api/v1/sys/role/list",
    method: "post",
    data: queryParams,
  });
}

/**
 * 获取角色的菜单ID集合
 *
 * @param queryParams
 */
export function getRoleMenuIds(roleId: number): AxiosPromise<any> {
  return request({
    url: "/api/v1/sys/role/queryMenuIds/" + roleId,
    method: "get",
  });
}

/**
 * 分配菜单权限给角色
 *
 * @param queryParams
 */
export function updateRoleMenus(
  roleId: number,
  data: number[]
): AxiosPromise<any> {
  return request({
    url: "/api/v1/sys/role/saveMenus",
    method: "post",
    data: {id: roleId,menuIds: data},
  });
}

/**
 * 添加角色
 *
 * @param data
 */
export function addRole(data: any) {
  return request({
    url: "/api/v1/sys/role/add",
    method: "post",
    data: data,
  });
}

/**
 * 更新角色
 *
 * @param id
 * @param data
 */
export function updateRole( data: any) {
  return request({
    url: "/api/v1/sys/role/update",
    method: "post",
    data: data,
  });
}

/**
 *
 * @param ids
 */
export function deleteRoles(ids: any) {
  return request({
    url: "/api/v1/sys/role/batch-del",
    method: "post",
    data: {ids: ids}
  });
}
