{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://genesiscode.dev/schemas/selfhost-closure-levels-v0.1.json",
  "title": "GenesisCode Self-Host Closure Levels v0.1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "kind",
    "version",
    "canonicalSpec",
    "canonicalSpecSha256",
    "stage0Contract",
    "stage0ContractIdentitySha256",
    "unitOfAssessment",
    "levelOrder",
    "applicabilityDispositions",
    "evidenceClasses",
    "levels",
    "aggregationRules",
    "promotionInvalidators",
    "forbiddenShortcuts",
    "nonclaims",
    "schema",
    "schemaSha256",
    "contentIdentitySha256"
  ],
  "properties": {
    "kind": { "const": "genesis/selfhost-closure-levels-v0.1" },
    "version": { "const": "0.1" },
    "canonicalSpec": { "const": "docs/spec/SELFHOST_CLOSURE_LEVELS_v0.1.md" },
    "canonicalSpecSha256": { "$ref": "#/$defs/sha256" },
    "stage0Contract": { "const": "docs/spec/STAGE0_TRUST_CONTRACT_v0.1.json" },
    "stage0ContractIdentitySha256": { "$ref": "#/$defs/sha256" },
    "unitOfAssessment": { "$ref": "#/$defs/nonEmptyUniqueStrings" },
    "levelOrder": {
      "const": ["H0", "H1", "H2", "H3", "H4"]
    },
    "applicabilityDispositions": {
      "type": "array",
      "minItems": 3,
      "maxItems": 3,
      "items": { "$ref": "#/$defs/disposition" }
    },
    "evidenceClasses": {
      "type": "array",
      "minItems": 5,
      "maxItems": 5,
      "items": { "$ref": "#/$defs/evidenceClass" }
    },
    "levels": {
      "type": "array",
      "minItems": 5,
      "maxItems": 5,
      "items": { "$ref": "#/$defs/level" }
    },
    "aggregationRules": { "$ref": "#/$defs/nonEmptyUniqueStrings" },
    "promotionInvalidators": { "$ref": "#/$defs/nonEmptyUniqueStrings" },
    "forbiddenShortcuts": { "$ref": "#/$defs/nonEmptyUniqueStrings" },
    "nonclaims": { "$ref": "#/$defs/nonEmptyUniqueStrings" },
    "schema": { "const": "docs/spec/SELFHOST_CLOSURE_LEVELS_v0.1.schema.json" },
    "schemaSha256": { "$ref": "#/$defs/sha256" },
    "contentIdentitySha256": { "$ref": "#/$defs/sha256" }
  },
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "slug": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "nonEmptyUniqueStrings": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 1 }
    },
    "disposition": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "ledgerValue", "criteria", "canSatisfyPrerequisite", "countsTowardAggregate"],
      "properties": {
        "id": { "enum": ["applicable", "residual-stage0", "not-semantic-decision"] },
        "ledgerValue": { "enum": ["H0-H4", "N/A"] },
        "criteria": { "$ref": "#/$defs/nonEmptyUniqueStrings" },
        "canSatisfyPrerequisite": { "type": "boolean" },
        "countsTowardAggregate": { "type": "boolean" }
      }
    },
    "evidenceClass": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "requiredFields", "minimumControls"],
      "properties": {
        "id": {
          "enum": [
            "route-custody",
            "implementation-conformance",
            "production-authority",
            "bootstrap-fixpoint",
            "independent-conformance"
          ]
        },
        "requiredFields": { "$ref": "#/$defs/nonEmptyUniqueStrings" },
        "minimumControls": { "$ref": "#/$defs/nonEmptyUniqueStrings" }
      }
    },
    "level": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "requiresLevels",
        "requiredEvidenceClasses",
        "predicates",
        "negativeControls",
        "nonclaims"
      ],
      "properties": {
        "id": { "enum": ["H0", "H1", "H2", "H3", "H4"] },
        "name": { "$ref": "#/$defs/slug" },
        "requiresLevels": {
          "type": "array",
          "uniqueItems": true,
          "items": { "enum": ["H0", "H1", "H2", "H3"] }
        },
        "requiredEvidenceClasses": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "enum": [
              "route-custody",
              "implementation-conformance",
              "production-authority",
              "bootstrap-fixpoint",
              "independent-conformance"
            ]
          }
        },
        "predicates": { "$ref": "#/$defs/nonEmptyUniqueStrings" },
        "negativeControls": { "$ref": "#/$defs/nonEmptyUniqueStrings" },
        "nonclaims": { "$ref": "#/$defs/nonEmptyUniqueStrings" }
      }
    }
  }
}
