{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "methodVersion": {
      "const": "1.0.0"
    },
    "request": {
      "$ref": "input.schema.json"
    },
    "revision": {
      "type": "integer",
      "minimum": 1
    },
    "status": {
      "enum": [
        "active",
        "blocked",
        "complete"
      ]
    },
    "stages": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "status": {
            "enum": [
              "not_started",
              "in_progress",
              "blocked",
              "verification_pending",
              "complete"
            ]
          },
          "evidence": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "path": {
                  "type": "string",
                  "minLength": 1
                },
                "sha256": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                "bytes": {
                  "type": "integer",
                  "minimum": 0
                },
                "source": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "path",
                "sha256",
                "bytes",
                "source"
              ]
            }
          },
          "checks": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "criterion": {
                  "type": "string",
                  "minLength": 1
                },
                "passed": {
                  "type": "boolean"
                },
                "evidence": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "criterion",
                "passed",
                "evidence"
              ]
            }
          },
          "approval": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "reviewer": {
                    "type": "string",
                    "minLength": 1
                  },
                  "note": {
                    "type": "string",
                    "minLength": 1
                  },
                  "at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "scope": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                },
                "required": [
                  "reviewer",
                  "note",
                  "at",
                  "scope"
                ]
              }
            ]
          },
          "retries": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10
          }
        },
        "required": [
          "id",
          "status",
          "evidence",
          "checks",
          "approval",
          "retries"
        ]
      }
    },
    "history": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "sequence": {
            "type": "integer",
            "minimum": 1
          },
          "at": {
            "type": "string",
            "format": "date-time"
          },
          "actor": {
            "type": "string",
            "minLength": 1
          },
          "action": {
            "type": "string",
            "minLength": 1
          },
          "detail": {
            "type": "object"
          },
          "previous": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            ]
          },
          "digest": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        },
        "required": [
          "sequence",
          "at",
          "actor",
          "action",
          "detail",
          "previous",
          "digest"
        ]
      }
    },
    "nextAction": {
      "type": "string",
      "minLength": 1
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "delivery": {
      "$ref": "output.schema.json"
    }
  },
  "required": [
    "schemaVersion",
    "methodVersion",
    "request",
    "revision",
    "status",
    "stages",
    "history",
    "nextAction",
    "updatedAt"
  ]
}
