import {
  publishWorkspaceDeleted
} from "./chunk-BUAYVN3C.mjs";
import {
  getDynamoDataService
} from "./chunk-6BB4CRSS.mjs";
import {
  deleteDataEntityById
} from "./chunk-V6AO5T57.mjs";
import {
  getDynamoControlService
} from "./chunk-EUIP2U5F.mjs";

// src/data/operations/control/tenant/tenant-delete-operation.ts
async function deleteTenantOperation(params) {
  const { id, tableName } = params;
  const service = getDynamoControlService(tableName);
  await service.entities.tenant.delete({ tenantId: id, sk: "CURRENT" }).go();
}

// src/data/operations/data/organization/organization-delete-operation.ts
async function deleteOrganizationOperation(params) {
  const { context, id, tableName } = params;
  const { tenantId, workspaceId } = context;
  const service = getDynamoDataService(tableName);
  await deleteDataEntityById(
    service.entities.organization,
    tenantId,
    workspaceId,
    id
  );
}

// src/data/operations/control/workspace/workspace-delete-operation.ts
async function deleteWorkspaceOperation(params) {
  const { context, id, tableName } = params;
  const { tenantId } = context;
  const service = getDynamoControlService(tableName);
  const existing = await service.entities.workspace.get({ tenantId, id, sk: "CURRENT" }).go();
  const workspaceExisted = existing.data !== null;
  await service.entities.workspace.delete({ tenantId, id, sk: "CURRENT" }).go();
  await deleteOrganizationOperation({
    context: { ...context, workspaceId: id },
    id,
    tableName
  });
  if (workspaceExisted) {
    await publishWorkspaceDeleted(context, {
      workspaceId: id,
      tenantId
    });
  }
}

export {
  deleteTenantOperation,
  deleteOrganizationOperation,
  deleteWorkspaceOperation
};
//# sourceMappingURL=chunk-3PS5R367.mjs.map