"use client";
import { HttpResponseError } from '@datatechsolutions/shared-domain/common';

// src/platform/windsock-admin-client.ts
var _adminClient = null;
var _issuer = null;
var _authFetch = fetch;
function setWindsockAdminClient(client, issuer, authFetch) {
  _adminClient = client;
  _issuer = issuer.replace(/\/$/, "");
  _authFetch = authFetch;
}
function requireClient() {
  if (!_adminClient) {
    throw new Error("Windsock admin client not initialized \u2014 did providers mount?");
  }
  return _adminClient;
}
async function listUsers(params) {
  return requireClient().listUsers(params);
}
async function createUser(data) {
  return requireClient().createUser(data);
}
async function updateUser(userId, data) {
  return requireClient().updateUser(userId, data);
}
async function deleteUser(userId) {
  return requireClient().deleteUser(userId);
}
async function resetUserPassword(userId, password) {
  return requireClient().resetUserPassword(userId, password);
}
async function listOrganizations() {
  return requireClient().listOrganizations();
}
async function createOrganization(data) {
  return requireClient().createOrganization(data);
}
async function updateOrganization(organizationId, data) {
  return requireClient().updateOrganization(organizationId, data);
}
async function deleteOrganization(organizationId) {
  return requireClient().deleteOrganization(organizationId);
}
async function listOrganizationMembers(organizationId) {
  return requireClient().listOrganizationMembers(organizationId);
}
async function addOrganizationMember(organizationId, userId, role) {
  return requireClient().addOrganizationMember(organizationId, userId, role);
}
async function removeOrganizationMember(organizationId, userId) {
  return requireClient().removeOrganizationMember(organizationId, userId);
}
async function listOrganizationInvitations(organizationId) {
  return requireClient().listOrganizationInvitations(organizationId);
}
async function createOrganizationInvitation(organizationId, data) {
  return requireClient().createOrganizationInvitation(organizationId, data);
}
async function listOrganizationDomains(organizationId) {
  return requireClient().listOrganizationDomains(organizationId);
}
async function addOrganizationDomain(organizationId, domain) {
  return requireClient().addOrganizationDomain(organizationId, domain);
}
async function verifyOrganizationDomain(organizationId, domain) {
  return requireClient().verifyOrganizationDomain(organizationId, domain);
}
async function listPermissions() {
  return requireClient().listPermissions();
}
async function createPermission(data) {
  return requireClient().createPermission(data);
}
async function updatePermission(permissionId, data) {
  return requireClient().updatePermission(permissionId, data);
}
async function deletePermission(permissionId) {
  return requireClient().deletePermission(permissionId);
}
async function getUserPermissions(userId) {
  return requireClient().getUserPermissions(userId);
}
async function setUserPermissions(userId, permissionIds) {
  return requireClient().setUserPermissions(userId, permissionIds);
}
async function secretsRequest(path, init) {
  if (!_issuer) throw new Error("Windsock issuer not initialized");
  const response = await _authFetch(`${_issuer}${path}`, {
    ...init,
    credentials: init?.credentials ?? "include",
    headers: {
      "Content-Type": "application/json",
      ...init?.headers
    }
  });
  if (response.status === 204) return void 0;
  const payload = await response.json().catch(() => null);
  if (!response.ok) {
    const message = payload?.message ?? payload?.error ?? `HTTP ${response.status}: ${response.statusText}`;
    throw new HttpResponseError(message, response.status);
  }
  if (payload && typeof payload === "object" && "success" in payload && payload.success && "data" in payload) {
    return payload.data;
  }
  return payload;
}
async function listSecrets(organizationId) {
  return secretsRequest(`/organizations/${encodeURIComponent(organizationId)}/secrets`);
}
async function getSecret(organizationId, secretId) {
  return secretsRequest(`/organizations/${encodeURIComponent(organizationId)}/secrets/${encodeURIComponent(secretId)}`);
}
async function createSecret(organizationId, input) {
  return secretsRequest(`/organizations/${encodeURIComponent(organizationId)}/secrets`, {
    method: "POST",
    body: JSON.stringify(input)
  });
}
async function rotateSecret(organizationId, secretId, input) {
  return secretsRequest(`/organizations/${encodeURIComponent(organizationId)}/secrets/${encodeURIComponent(secretId)}`, {
    method: "PATCH",
    body: JSON.stringify(input)
  });
}
async function disableSecret(organizationId, secretId) {
  return secretsRequest(`/organizations/${encodeURIComponent(organizationId)}/secrets/${encodeURIComponent(secretId)}`, {
    method: "DELETE"
  });
}

export { addOrganizationDomain, addOrganizationMember, createOrganization, createOrganizationInvitation, createPermission, createSecret, createUser, deleteOrganization, deletePermission, deleteUser, disableSecret, getSecret, getUserPermissions, listOrganizationDomains, listOrganizationInvitations, listOrganizationMembers, listOrganizations, listPermissions, listSecrets, listUsers, removeOrganizationMember, resetUserPassword, rotateSecret, setUserPermissions, setWindsockAdminClient, updateOrganization, updatePermission, updateUser, verifyOrganizationDomain };
//# sourceMappingURL=chunk-UHHPBREK.mjs.map
//# sourceMappingURL=chunk-UHHPBREK.mjs.map