import { sql } from "kysely";
import { createLogger } from "@open-mercato/shared/lib/logger";
const logger = createLogger("translations").child({ component: "cleanup" });
const metadata = { event: "query_index.delete_one", persistent: false };
async function handle(payload, ctx) {
  const entityType = String(payload?.entityType || "");
  const recordId = String(payload?.recordId || "");
  if (!entityType || !recordId) return;
  const organizationId = payload?.organizationId ?? null;
  const tenantId = payload?.tenantId ?? null;
  try {
    const em = ctx.resolve("em");
    const db = em.getKysely();
    await db.deleteFrom("entity_translations").where("entity_type", "=", entityType).where("entity_id", "=", recordId).where(sql`tenant_id is not distinct from ${tenantId}`).where(sql`organization_id is not distinct from ${organizationId}`).execute();
  } catch (err) {
    logger.warn("Failed to delete translations", { err });
  }
}
export {
  handle as default,
  metadata
};
//# sourceMappingURL=cleanup.js.map
