import {
  getDynamoDataService
} from "./chunk-6BB4CRSS.mjs";
import {
  batchGetWithRetry,
  dispatchListMode,
  listDataEntitiesByWorkspace
} from "./chunk-V6AO5T57.mjs";
import {
  SHARD_COUNT,
  getDynamoControlService
} from "./chunk-EUIP2U5F.mjs";

// src/data/operations/data/practitionerrole/practitionerrole-list-operation.ts
async function listPractitionerRolesOperation(params) {
  const { context, tableName, mode } = params;
  const { tenantId, workspaceId } = context;
  const service = getDynamoDataService(tableName);
  return listDataEntitiesByWorkspace(
    service.entities.practitionerrole,
    tenantId,
    workspaceId,
    mode
  );
}

// src/data/operations/control/roleassignment/roleassignment-list-operation.ts
var SK = "CURRENT";
async function listRoleAssignmentsOperation(params) {
  const { context, tableName, mode = "full" } = params;
  const tenantId = context.tenantId;
  const service = getDynamoControlService(tableName);
  const shardResults = await Promise.all(
    Array.from(
      { length: SHARD_COUNT },
      (_, shard) => service.entities.roleAssignment.query.gsi1({ tenantId, gsi1Shard: String(shard) }).go()
    )
  );
  return dispatchListMode(mode, shardResults, {
    // Strongly-consistent BatchGet on the base table so a role change is
    // reflected immediately by the read-back the admin-console dropdowns
    // issue right after their PUT/POST. Without it the eventually-consistent
    // hydration can return the *previous* role, making the dropdown appear
    // to revert (#1347).
    hydrate: (orderedIds) => batchGetWithRetry(
      service.entities.roleAssignment,
      orderedIds.map((id) => ({ tenantId, id, sk: SK })),
      { consistent: true }
    ),
    getId: (item) => item.id,
    buildEntry: (id, item) => ({
      id,
      resource: {
        resourceType: "RoleAssignment",
        id,
        ...JSON.parse(item.resource)
      }
    }),
    buildSummaryEntry: (id, parsed) => ({
      id,
      resource: { resourceType: "RoleAssignment", id, ...parsed }
    })
  });
}

export {
  listPractitionerRolesOperation,
  listRoleAssignmentsOperation
};
//# sourceMappingURL=chunk-63POQTMP.mjs.map