{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ggaction.github.io/ggaction/schemas/task-packet.schema.json",
  "title": "ggaction compact task packet",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "packageVersion",
    "query",
    "matchedConstraints",
    "actionPlan",
    "exactCalls",
    "appliedOptions",
    "placeholderBindings",
    "unmatchedRequirements",
    "authoring",
    "unsupported",
    "unresolved",
    "candidates"
  ],
  "properties": {
    "schemaVersion": { "const": 5 },
    "packageVersion": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$"
    },
    "query": { "type": "string", "minLength": 1, "maxLength": 500 },
    "matchedConstraints": {
      "type": "array",
      "maxItems": 30,
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 3, "maxLength": 100 }
    },
    "actionPlan": {
      "type": "array",
      "maxItems": 20,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "step",
          "id",
          "kind",
          "name",
          "constraints",
          "requiredOptions",
          "signature",
          "route"
        ],
        "properties": {
          "step": { "type": "integer", "minimum": 1 },
          "id": { "type": "string", "minLength": 3 },
          "kind": { "enum": ["action", "runtime"] },
          "name": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9]*$" },
          "constraints": {
            "type": "array",
            "uniqueItems": true,
            "items": { "type": "string", "minLength": 3 }
          },
          "requiredOptions": {
            "type": "array",
            "uniqueItems": true,
            "items": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9]*$" }
          },
          "signature": { "type": "string", "minLength": 8 },
          "route": { "type": "string", "pattern": "^/reference/" }
        }
      }
    },
    "exactCalls": {
      "type": "array",
      "maxItems": 20,
      "items": { "type": "string", "minLength": 3, "maxLength": 700 }
    },
    "appliedOptions": {
      "type": "array",
      "maxItems": 30,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["owner", "option", "value", "source"],
        "properties": {
          "owner": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9]*$" },
          "option": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9]*$" },
          "value": { "type": "string", "minLength": 1, "maxLength": 300 },
          "source": { "type": "string", "minLength": 1, "maxLength": 180 }
        }
      }
    },
    "placeholderBindings": {
      "type": "array",
      "maxItems": 30,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "kind", "required", "usedBy", "reason"],
        "properties": {
          "name": { "type": "string", "minLength": 1, "maxLength": 80 },
          "kind": { "enum": ["binding", "field", "program", "resource", "runtime", "text"] },
          "required": { "type": "boolean" },
          "usedBy": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "uniqueItems": true,
            "items": { "type": "string", "minLength": 1, "maxLength": 80 }
          },
          "reason": { "type": "string", "minLength": 20, "maxLength": 240 }
        }
      }
    },
    "unmatchedRequirements": {
      "type": "array",
      "maxItems": 30,
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 1, "maxLength": 180 }
    },
    "authoring": {
      "type": "object",
      "additionalProperties": false,
      "required": ["imports", "initialize", "prerequisites", "steps"],
      "properties": {
        "imports": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 30, "maxLength": 90 }
        },
        "initialize": { "const": "let program = chart()" },
        "prerequisites": {
          "type": "array",
          "minItems": 0,
          "maxItems": 2,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "signature", "call", "bindings"],
            "properties": {
              "id": { "enum": ["action.createCanvas", "action.createData"] },
              "signature": { "type": "string", "minLength": 8, "maxLength": 180 },
              "call": { "type": "string", "minLength": 12, "maxLength": 180 },
              "bindings": {
                "type": "array",
                "maxItems": 4,
                "uniqueItems": true,
                "items": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9]*$" }
              }
            }
          }
        },
        "steps": {
          "type": "array",
          "maxItems": 20,
          "items": { "type": "string", "minLength": 3, "maxLength": 760 }
        }
      }
    },
    "unsupported": {
      "type": "array",
      "maxItems": 10,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["constraint", "reason"],
        "properties": {
          "constraint": { "type": "string", "pattern": "^unsupported\\." },
          "reason": { "type": "string", "minLength": 10, "maxLength": 240 }
        }
      }
    },
    "unresolved": {
      "type": "array",
      "maxItems": 30,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["constraint", "reason", "resources"],
        "properties": {
          "constraint": { "type": "string", "minLength": 3 },
          "reason": { "type": "string", "minLength": 10, "maxLength": 240 },
          "resources": {
            "type": "array",
            "minItems": 1,
            "maxItems": 2,
            "uniqueItems": true,
            "items": { "type": "string", "pattern": "^ggaction://docs/[a-z0-9-]+$" }
          }
        }
      }
    },
    "candidates": {
      "type": "array",
      "maxItems": 3,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "kind", "name", "route"],
        "properties": {
          "id": { "type": "string", "minLength": 3 },
          "kind": { "enum": ["action", "runtime"] },
          "name": { "type": "string", "minLength": 2 },
          "route": { "type": "string", "pattern": "^/reference/" }
        }
      }
    }
  }
}
