{
  "$id": "https://opendatafabric.org/schemas/flows/v1alpha1/FlowTriggerInput",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "canonicalType": "https://opendatafabric.org/schemas/flows/v1alpha1/FlowTrigger",
  "description": "Condition that causes a flow to be executed.",
  "$defs": {
    "Manual": {
      "description": "Triggers the flow via an API call or UI action.",
      "type": "object",
      "required": [],
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true,
          "description": "Allows to pause an individual trigger."
        },
        "cooldown": {
          "type": "string",
          "format": "duration",
          "description": "Minimum interval between activations of the trigger. If the trigger fires again within the interval, the activation is postponed until the interval ends, batching multiple activations into one flow run."
        },
        "cooldownMaxBatch": {
          "type": "integer",
          "format": "uint64",
          "description": "If the trigger is activated this many times during the `cooldown` interval, it fires without waiting for the interval to end."
        }
      }
    },
    "Schedule": {
      "description": "Triggers the flow on a cron schedule.",
      "type": "object",
      "required": [
        "cron"
      ],
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true,
          "description": "Allows to pause an individual trigger."
        },
        "cooldown": {
          "type": "string",
          "format": "duration",
          "description": "Minimum interval between activations of the trigger. If the trigger fires again within the interval, the activation is postponed until the interval ends, batching multiple activations into one flow run."
        },
        "cooldownMaxBatch": {
          "type": "integer",
          "format": "uint64",
          "description": "If the trigger is activated this many times during the `cooldown` interval, it fires without waiting for the interval to end."
        },
        "cron": {
          "type": "string",
          "description": "Cron5 expression defining the schedule e.g. `@daily` or `*/30 * * * *`."
        }
      }
    },
    "Interval": {
      "description": "Triggers the flow at regular intervals.",
      "type": "object",
      "required": [
        "interval"
      ],
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true,
          "description": "Allows to pause an individual trigger."
        },
        "cooldown": {
          "type": "string",
          "format": "duration",
          "description": "Minimum interval between activations of the trigger. If the trigger fires again within the interval, the activation is postponed until the interval ends, batching multiple activations into one flow run."
        },
        "cooldownMaxBatch": {
          "type": "integer",
          "format": "uint64",
          "description": "If the trigger is activated this many times during the `cooldown` interval, it fires without waiting for the interval to end."
        },
        "interval": {
          "type": "string",
          "format": "duration",
          "description": "Interval between activations e.g. `15m`."
        }
      }
    },
    "Event": {
      "description": "Triggers the flow when an event bus event matching one of the filters is observed.",
      "type": "object",
      "required": [
        "events"
      ],
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true,
          "description": "Allows to pause an individual trigger."
        },
        "events": {
          "$ref": "https://opendatafabric.org/schemas/events/v1alpha1/EventFilter",
          "description": "Filters the event by type and fields.",
          "unevaluatedProperties": false
        },
        "cooldown": {
          "type": "string",
          "format": "duration",
          "description": "Minimum interval between activations of the trigger. If the trigger fires again within the interval, the activation is postponed until the interval ends, batching multiple activations into one flow run."
        },
        "cooldownMaxBatch": {
          "type": "integer",
          "format": "uint64",
          "description": "If the trigger is activated this many times during the `cooldown` interval, it fires without waiting for the interval to end."
        }
      }
    },
    "Source": {
      "description": "Triggers the flow when a source receives new data, with optional batching controls.",
      "type": "object",
      "required": [
        "source"
      ],
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true,
          "description": "Allows to pause an individual trigger."
        },
        "cooldown": {
          "type": "string",
          "format": "duration",
          "description": "Minimum interval between activations of the trigger. If the trigger fires again within the interval, the activation is postponed until the interval ends, batching multiple activations into one flow run."
        },
        "cooldownMaxBatch": {
          "type": "integer",
          "format": "uint64",
          "description": "If the trigger is activated this many times during the `cooldown` interval, it fires without waiting for the interval to end."
        },
        "source": {
          "$ref": "https://opendatafabric.org/schemas/resources/v1alpha1/ResourceRef",
          "description": "Reference to the source resource that drives this trigger.",
          "unevaluatedProperties": false
        },
        "minRecordsToAwait": {
          "type": "integer",
          "format": "uint64",
          "description": "Minimum number of new records to accumulate before triggering."
        },
        "maxAwaitInterval": {
          "type": "string",
          "format": "duration",
          "description": "Maximum time to wait for `minRecordsToAwait` before triggering anyway e.g. `1h`."
        }
      }
    },
    "InputsUpdated": {
      "description": "Triggers the flow when inputs of a derivative dataset receive new data, with optional batching controls.",
      "type": "object",
      "required": [],
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true,
          "description": "Allows to pause an individual trigger."
        },
        "cooldown": {
          "type": "string",
          "format": "duration",
          "description": "Minimum interval between activations of the trigger. If the trigger fires again within the interval, the activation is postponed until the interval ends, batching multiple activations into one flow run."
        },
        "cooldownMaxBatch": {
          "type": "integer",
          "format": "uint64",
          "description": "If the trigger is activated this many times during the `cooldown` interval, it fires without waiting for the interval to end."
        },
        "target": {
          "$ref": "https://opendatafabric.org/schemas/datasets/v1alpha1/DatasetSelector",
          "description": "Selector of derivative datasets whose inputs are watched. Defaults to the flow-level target when omitted.",
          "unevaluatedProperties": false
        },
        "minRecordsToAwait": {
          "type": "integer",
          "format": "uint64",
          "description": "Minimum number of new input records to accumulate before triggering."
        },
        "maxAwaitInterval": {
          "type": "string",
          "format": "duration",
          "description": "Maximum time to wait for `minRecordsToAwait` before triggering anyway e.g. `1h`."
        }
      }
    }
  },
  "oneOf": [
    {
      "allOf": [
        { "properties": { "kind": { "type": "string", "const": "Manual" } }, "required": ["kind"] },
        { "$ref": "#/$defs/Manual" }
      ]
    },
    {
      "allOf": [
        { "properties": { "kind": { "type": "string", "const": "Schedule" } }, "required": ["kind"] },
        { "$ref": "#/$defs/Schedule" }
      ]
    },
    {
      "allOf": [
        { "properties": { "kind": { "type": "string", "const": "Interval" } }, "required": ["kind"] },
        { "$ref": "#/$defs/Interval" }
      ]
    },
    {
      "allOf": [
        { "properties": { "kind": { "type": "string", "const": "Event" } }, "required": ["kind"] },
        { "$ref": "#/$defs/Event" }
      ]
    },
    {
      "allOf": [
        { "properties": { "kind": { "type": "string", "const": "Source" } }, "required": ["kind"] },
        { "$ref": "#/$defs/Source" }
      ]
    },
    {
      "allOf": [
        { "properties": { "kind": { "type": "string", "const": "InputsUpdated" } }, "required": ["kind"] },
        { "$ref": "#/$defs/InputsUpdated" }
      ]
    }
  ]
}
