import { RolesApi } from "omsorgcore-client-ts";
import { configFor, callApi } from "./apiClientHelpers.js";

// Kapselt /api/roles von omsorgCore (RolesController) über den generierten Client
// (omsorgcore-client-ts).
export async function listRoles(accessToken) {
  const api = new RolesApi(configFor(accessToken));
  return callApi(api.apiRolesGetRaw());
}

export async function getRole(accessToken, roleId) {
  const api = new RolesApi(configFor(accessToken));
  return callApi(api.apiRolesIdGetRaw({ id: roleId }));
}

export async function createRole(accessToken, payload) {
  const api = new RolesApi(configFor(accessToken));
  return callApi(api.apiRolesPostRaw({ createRoleRequest: payload }));
}

export async function updateRolePermissions(accessToken, roleId, payload) {
  const api = new RolesApi(configFor(accessToken));
  return callApi(api.apiRolesIdPermissionsPutRaw({ id: roleId, updateRolePermissionsRequest: payload }));
}

export async function deleteRole(accessToken, roleId) {
  const api = new RolesApi(configFor(accessToken));
  return callApi(api.apiRolesIdDeleteRaw({ id: roleId }));
}
