{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/rjaskonis/pi-feats/schemas/sequential-workflow-template.schema.json",
  "title": "Sequential Workflow Template",
  "description": "A versioned, reusable definition for a Sequential Workflow.",
  "type": "object",
  "additionalProperties": false,
  "required": ["version", "title", "source", "tasks"],
  "properties": {
    "version": {
      "const": 1,
      "description": "Template format version."
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 1000
    },
    "source": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2000,
      "description": "Human-readable provenance for the workflow definition."
    },
    "tasks": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["type", "instruction"],
        "properties": {
          "type": {
            "enum": ["action", "collect", "evaluate", "workflow"]
          },
          "instruction": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10000
          },
          "criteria": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10000
          }
        },
        "allOf": [
          {
            "if": {
              "properties": { "type": { "const": "collect" } },
              "required": ["type"]
            },
            "then": {
              "required": ["criteria"]
            }
          }
        ]
      }
    }
  }
}
