import { http } from "@/utils/http";

type Result = {
  code: number;
  message: string;
  data?: any;
};

export const getAllPermissions = () => {
  return http.request<Result>("get", "/permission/list");
};

export const getPermissionsGrouped = () => {
  return http.request<Result>("get", "/permission/list-grouped");
};

export const getPermissionsByModule = (moduleCode: string) => {
  return http.request<Result>("get", `/permission/module/${moduleCode}`);
};

export const getRolePermissionIds = (roleId: number) => {
  return http.request<Result>("get", `/permission/role/${roleId}`);
};

export const updateRolePermissions = (roleId: number, permissionIds: number[]) => {
  return http.request<Result>("post", `/permission/role/${roleId}`, {
    data: permissionIds
  });
};
