{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mathgraph.org/schemas/capability-evaluation-v1.schema.json",
  "title": "MathGraph capability evaluation v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "contract",
    "contract_sha256",
    "contract_size_bytes",
    "validation",
    "qualification",
    "qualification_receipt",
    "trust_policy",
    "freshness",
    "revocation",
    "supersession",
    "current_applicability",
    "action_authorization",
    "reason_codes"
  ],
  "properties": {
    "schema_version": {
      "const": "mathgraph.capability-evaluation.v1"
    },
    "contract": {
      "anyOf": [
        {
          "$ref": "#/$defs/identity"
        },
        {
          "type": "null"
        }
      ]
    },
    "contract_sha256": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "minLength": 64,
          "maxLength": 64
        },
        {
          "type": "null"
        }
      ]
    },
    "contract_size_bytes": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 0
        },
        {
          "type": "null"
        }
      ]
    },
    "validation": {
      "enum": [
        "VALID",
        "INVALID"
      ]
    },
    "qualification": {
      "enum": [
        "QUALIFIED_BOUNDED",
        "UNKNOWN"
      ]
    },
    "qualification_receipt": {
      "anyOf": [
        {
          "$ref": "#/$defs/artifact"
        },
        {
          "type": "null"
        }
      ]
    },
    "trust_policy": {
      "anyOf": [
        {
          "$ref": "#/$defs/artifact"
        },
        {
          "type": "null"
        }
      ]
    },
    "freshness": {
      "enum": [
        "NOT_CHECKED",
        "CURRENT",
        "STALE",
        "UNKNOWN"
      ]
    },
    "revocation": {
      "enum": [
        "NOT_CHECKED",
        "NOT_REVOKED",
        "REVOKED",
        "UNKNOWN"
      ]
    },
    "supersession": {
      "enum": [
        "NOT_CHECKED",
        "NOT_SUPERSEDED",
        "SUPERSEDED",
        "UNKNOWN"
      ]
    },
    "current_applicability": {
      "enum": [
        "APPLICABLE",
        "NOT_APPLICABLE",
        "UNKNOWN"
      ]
    },
    "action_authorization": {
      "const": "NONE"
    },
    "reason_codes": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "\\S"
      },
      "minItems": 1,
      "uniqueItems": true
    }
  },
  "$defs": {
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "locator",
        "sha256",
        "size_bytes",
        "media_type"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "\\S"
        },
        "locator": {
          "type": "string",
          "pattern": "\\S"
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "minLength": 64,
          "maxLength": 64
        },
        "size_bytes": {
          "type": "integer",
          "minimum": 0
        },
        "media_type": {
          "type": "string",
          "pattern": "\\S"
        }
      }
    },
    "identity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "version",
        "profile"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "\\S"
        },
        "version": {
          "type": "string",
          "pattern": "\\S"
        },
        "profile": {
          "type": "string",
          "pattern": "\\S"
        }
      }
    }
  },
  "description": "Structural validation is orthogonal to qualification, freshness, revocation, supersession, applicability and authorization. A receipt and trust-policy pin are necessary but not sufficient for admission. No evaluation authorizes execution or introduces a mathematical terminal form.",
  "allOf": [
    {
      "if": {
        "properties": {
          "validation": {
            "const": "INVALID"
          }
        }
      },
      "then": {
        "properties": {
          "contract": {
            "type": "null"
          },
          "contract_sha256": {
            "type": "null"
          },
          "contract_size_bytes": {
            "type": "null"
          },
          "qualification": {
            "const": "UNKNOWN"
          },
          "qualification_receipt": {
            "type": "null"
          },
          "trust_policy": {
            "type": "null"
          },
          "current_applicability": {
            "const": "UNKNOWN"
          }
        }
      },
      "else": {
        "properties": {
          "contract": {
            "$ref": "#/$defs/identity"
          },
          "contract_sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "minLength": 64,
            "maxLength": 64
          },
          "contract_size_bytes": {
            "type": "integer",
            "minimum": 0
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "qualification": {
            "const": "QUALIFIED_BOUNDED"
          }
        }
      },
      "then": {
        "properties": {
          "validation": {
            "const": "VALID"
          },
          "qualification_receipt": {
            "$ref": "#/$defs/artifact"
          },
          "trust_policy": {
            "$ref": "#/$defs/artifact"
          }
        }
      }
    }
  ]
}
