import {
  chunkOwningChildRows,
  listOwningChildProjectionsOperation
} from "./chunk-Q3MKITPY.mjs";
import "./chunk-QJDHVMKT.mjs";
import "./chunk-FYHBHHWK.mjs";
import "./chunk-EUIP2U5F.mjs";
import "./chunk-TRY7JGWO.mjs";
import "./chunk-KMEWULMX.mjs";
import "./chunk-LZOMFHX3.mjs";

// src/workflows/control-plane/owning-delete-cascade/list-chunks.handler.ts
import { randomUUID } from "crypto";
var handler = async (input) => {
  const cursors = {};
  if (input.cursors) {
    for (const [key, value] of Object.entries(input.cursors)) {
      cursors[key] = value;
    }
  }
  const page = await listOwningChildProjectionsOperation({
    ownerType: input.ownerType,
    ownerId: input.ownerId,
    tenantId: input.tenantId,
    cursors
  });
  const chunks = chunkOwningChildRows(page.items).map(
    (rows) => ({
      ownerType: input.ownerType,
      ownerId: input.ownerId,
      tenantId: input.tenantId,
      rows: rows.map((row) => ({ entity: row.entity, key: row.key })),
      chunkToken: randomUUID()
    })
  );
  const priorRemoved = input.projectionsRemoved ?? 0;
  const priorChunks = input.chunkCount ?? 0;
  const projectionsRemoved = priorRemoved + page.items.length;
  const chunkCount = priorChunks + chunks.length;
  return {
    ownerType: input.ownerType,
    ownerId: input.ownerId,
    tenantId: input.tenantId,
    cursors: page.cursors,
    chunks,
    exhausted: page.exhausted,
    projectionsRemoved,
    chunkCount
  };
};
export {
  handler
};
//# sourceMappingURL=list-chunks.handler.mjs.map