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

// Kapselt /api/users von omsorgCore (UsersController) über den generierten Client
// (omsorgcore-client-ts).
export async function listUsers(accessToken) {
  const api = new UsersApi(configFor(accessToken));
  return callApi(api.apiUsersGetRaw());
}

export async function createUser(accessToken, payload) {
  const api = new UsersApi(configFor(accessToken));
  return callApi(api.apiUsersPostRaw({ createUserRequest: payload }));
}

export async function listPermissionOverrides(accessToken, userId) {
  const api = new UsersApi(configFor(accessToken));
  return callApi(api.apiUsersIdPermissionOverridesGetRaw({ id: userId }));
}

export async function addPermissionOverride(accessToken, userId, payload) {
  const api = new UsersApi(configFor(accessToken));
  return callApi(api.apiUsersIdPermissionOverridesPostRaw({ id: userId, addUserPermissionOverrideRequest: payload }));
}

export async function deletePermissionOverride(accessToken, userId, overrideId) {
  const api = new UsersApi(configFor(accessToken));
  return callApi(api.apiUsersIdPermissionOverridesOverrideIdDeleteRaw({ id: userId, overrideId }));
}

export async function updateUser(accessToken, userId, payload) {
  const api = new UsersApi(configFor(accessToken));
  return callApi(api.apiUsersIdPutRaw({ id: userId, updateUserRequest: payload }));
}

export async function resetPassword(accessToken, userId, payload) {
  const api = new UsersApi(configFor(accessToken));
  return callApi(api.apiUsersIdResetPasswordPostRaw({ id: userId, resetUserPasswordRequest: payload }));
}
