// runtime/subsystems/integration/detection-config.schema.ts
import { z } from "zod";
var FieldMappingSchema = z.object({
  source: z.string().min(1),
  target: z.string().min(1),
  transform: z.string().min(1).optional()
});
var ResolvedFilterSchema = z.object({
  field: z.string().min(1),
  op: z.enum(["eq", "neq", "in", "nin", "gt", "gte", "lt", "lte"]),
  value: z.unknown()
});
var SystemModstampCursorSchema = z.object({
  kind: z.literal("systemModstamp"),
  field: z.string().min(1)
});
var ReplayIdCursorSchema = z.object({
  kind: z.literal("replayId"),
  field: z.string().min(1)
});
var TimestampCursorSchema = z.object({
  kind: z.literal("timestamp"),
  field: z.string().min(1)
});
var EventIdCursorSchema = z.object({
  kind: z.literal("eventId"),
  field: z.string().min(1)
});
var HistoryIdCursorSchema = z.object({
  kind: z.literal("historyId"),
  field: z.string().min(1)
});
var SyncTokenCursorSchema = z.object({
  kind: z.literal("syncToken"),
  field: z.string().min(1)
});
var CursorStrategySchema = z.discriminatedUnion("kind", [
  SystemModstampCursorSchema,
  ReplayIdCursorSchema,
  TimestampCursorSchema,
  EventIdCursorSchema,
  HistoryIdCursorSchema,
  SyncTokenCursorSchema
]);
var CURSOR_DIVISIBILITY = {
  systemModstamp: true,
  timestamp: true,
  replayId: true,
  eventId: false,
  historyId: false,
  syncToken: false
};
function isDivisibleCursor(kind) {
  return CURSOR_DIVISIBILITY[kind];
}
var PollDetectionSchema = z.object({
  cursor: CursorStrategySchema,
  provenance: z.enum(["poll", "cdc"]).optional()
});
var WebhookDetectionSchema = z.object({
  eventIdField: z.string().min(1).optional()
});
var PollModeSchema = z.object({
  mode: z.literal("poll"),
  poll: PollDetectionSchema,
  mapping: z.array(FieldMappingSchema).min(1),
  filters: z.array(ResolvedFilterSchema).default([])
});
var WebhookModeSchema = z.object({
  mode: z.literal("webhook"),
  webhook: WebhookDetectionSchema,
  mapping: z.array(FieldMappingSchema).min(1),
  filters: z.array(ResolvedFilterSchema).default([])
});
var DetectionConfigSchema = z.discriminatedUnion("mode", [
  PollModeSchema,
  WebhookModeSchema
]);

export {
  FieldMappingSchema,
  ResolvedFilterSchema,
  CursorStrategySchema,
  CURSOR_DIVISIBILITY,
  isDivisibleCursor,
  PollDetectionSchema,
  WebhookDetectionSchema,
  DetectionConfigSchema
};
//# sourceMappingURL=chunk-5TK7MEN4.js.map