// src/data/operations/control/membership/membership-user-projection.ts
import { normalizeLabel } from "@openhi/types";
var MISSING_NAME_SENTINEL = "-";
function buildMembershipUserProjectionSkTenantLane(params) {
  const normalizedTenantName = typeof params.denormalizedTenantName === "string" && params.denormalizedTenantName.length > 0 ? normalizeLabel(params.denormalizedTenantName) : MISSING_NAME_SENTINEL;
  return `MEMBERSHIP#TENANT#${normalizedTenantName}#TID#${params.tenantId}#${params.membershipId}`;
}
function buildMembershipUserProjectionSkWorkspaceLane(params) {
  const normalizedWorkspaceName = typeof params.denormalizedWorkspaceName === "string" && params.denormalizedWorkspaceName.length > 0 ? normalizeLabel(params.denormalizedWorkspaceName) : MISSING_NAME_SENTINEL;
  return `MEMBERSHIP#WORKSPACE#TID#${params.tenantId}#${normalizedWorkspaceName}#WID#${params.workspaceId}#${params.membershipId}`;
}
function buildMembershipUserProjectionItem(input) {
  if (!input.userId || input.userId.length === 0) {
    return void 0;
  }
  const hasWorkspace = typeof input.workspaceId === "string" && input.workspaceId.length > 0;
  const sk = hasWorkspace ? buildMembershipUserProjectionSkWorkspaceLane({
    tenantId: input.tenantId,
    workspaceId: input.workspaceId,
    membershipId: input.membershipId,
    denormalizedWorkspaceName: input.denormalizedWorkspaceName
  }) : buildMembershipUserProjectionSkTenantLane({
    tenantId: input.tenantId,
    membershipId: input.membershipId,
    denormalizedTenantName: input.denormalizedTenantName
  });
  return {
    userId: input.userId,
    sk,
    tenantId: input.tenantId,
    workspaceId: hasWorkspace ? input.workspaceId : void 0,
    membershipId: input.membershipId,
    summary: input.summary,
    vid: input.vid,
    lastUpdated: input.lastUpdated,
    denormalizedTenantName: input.denormalizedTenantName,
    denormalizedUserName: input.denormalizedUserName,
    denormalizedWorkspaceName: hasWorkspace ? input.denormalizedWorkspaceName : void 0
  };
}
function extractReferenceSlug(resource, fieldName) {
  const field = resource[fieldName];
  if (!field || typeof field !== "object") {
    return void 0;
  }
  const reference = field.reference;
  if (typeof reference !== "string" || reference.length === 0) {
    return void 0;
  }
  const slash = reference.lastIndexOf("/");
  const tail = slash >= 0 ? reference.slice(slash + 1) : reference;
  return tail.length > 0 ? tail : void 0;
}

export {
  buildMembershipUserProjectionSkTenantLane,
  buildMembershipUserProjectionSkWorkspaceLane,
  buildMembershipUserProjectionItem,
  extractReferenceSlug
};
//# sourceMappingURL=chunk-I6LUPJUY.mjs.map