{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://platoskallipolis.com/schemas/revalidation-dry-run-lineage-ledger.v1.json",
  "title": "Plato's Kallipolis revalidation dry-run lineage ledger",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "state", "snapshotAt", "input", "lineageLedger", "counts", "states", "continuity", "executionBoundary", "privacy"],
  "properties": {
    "schema": { "const": "kallipolis.revalidation-dry-run-lineage-ledger.v1" },
    "state": { "const": "verified-local-audit-evidence" },
    "snapshotAt": { "type": "string", "format": "date-time" },
    "input": { "$ref": "#/$defs/inputReference" },
    "lineageLedger": { "$ref": "#/$defs/artifactReference" },
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["statesVerified", "manifestsVerified", "dryRunArtifactsVerified", "exactBindingsByState", "executionBatchesByState", "totalDryRunPlannedBindings", "totalExecutedBindings", "totalNetworkCalls", "productionPromotionEligible", "lifecycleChangesApplied"],
      "properties": {
        "statesVerified": { "const": 3 },
        "manifestsVerified": { "const": 3 },
        "dryRunArtifactsVerified": { "const": 6 },
        "exactBindingsByState": { "const": [244, 335, 336] },
        "executionBatchesByState": { "const": [15, 20, 20] },
        "totalDryRunPlannedBindings": { "const": 927 },
        "totalExecutedBindings": { "const": 0 },
        "totalNetworkCalls": { "const": 0 },
        "productionPromotionEligible": { "const": 0 },
        "lifecycleChangesApplied": { "const": 0 }
      }
    },
    "states": { "type": "array", "minItems": 3, "maxItems": 3, "items": { "$ref": "#/$defs/readinessState" } },
    "continuity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["stateOrder", "manifestRawHashesContinueVerifiedLineage", "crossStateSubstitutionAccepted"],
      "properties": {
        "stateOrder": { "const": ["recovery-aware-244", "first-100-merged-335", "complete-state-336"] },
        "manifestRawHashesContinueVerifiedLineage": { "const": true },
        "crossStateSubstitutionAccepted": { "const": false }
      }
    },
    "executionBoundary": { "$ref": "#/$defs/executionBoundary" },
    "privacy": { "$ref": "#/$defs/privacy" }
  },
  "$defs": {
    "digest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
    "inputReference": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "rawHash"],
      "properties": {
        "path": { "const": "ops/revalidation-dry-run-lineage-audit-input.json" },
        "rawHash": { "$ref": "#/$defs/digest" }
      }
    },
    "artifactReference": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "rawHash", "canonicalHash"],
      "properties": {
        "path": { "type": "string", "pattern": "^ops/evidence/[A-Za-z0-9._/-]+\\.json$" },
        "rawHash": { "$ref": "#/$defs/digest" },
        "canonicalHash": { "$ref": "#/$defs/digest" }
      }
    },
    "stateCounts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["exactBindings", "expiryGroups", "executionBatches", "dryRunArtifacts", "dryRunPlannedBindings"],
      "properties": {
        "exactBindings": { "enum": [244, 335, 336] },
        "expiryGroups": { "enum": [11, 16] },
        "executionBatches": { "enum": [15, 20] },
        "dryRunArtifacts": { "const": 2 },
        "dryRunPlannedBindings": { "enum": [248, 339, 340] }
      }
    },
    "manifest": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "rawHash", "canonicalHash", "exactBindingSetHash", "lineageRawHashVerified"],
      "properties": {
        "path": { "type": "string", "pattern": "^ops/evidence/[A-Za-z0-9._/-]+\\.json$" },
        "rawHash": { "$ref": "#/$defs/digest" },
        "canonicalHash": { "$ref": "#/$defs/digest" },
        "exactBindingSetHash": { "$ref": "#/$defs/digest" },
        "lineageRawHashVerified": { "const": true }
      }
    },
    "dryRun": {
      "type": "object",
      "additionalProperties": false,
      "required": ["role", "path", "rawHash", "canonicalHash", "schema", "state", "manifestRawHash", "selectedBatches", "plannedBindings", "executedBindings", "networkCallsMade"],
      "properties": {
        "role": { "enum": ["first-batch", "matrix"] },
        "path": { "type": "string", "pattern": "^ops/evidence/[A-Za-z0-9._/-]+\\.json$" },
        "rawHash": { "$ref": "#/$defs/digest" },
        "canonicalHash": { "$ref": "#/$defs/digest" },
        "schema": { "enum": ["kallipolis.readiness-revalidation-batch-dry-run.v1", "kallipolis.readiness-revalidation-dry-run-matrix.v1"] },
        "state": { "const": "dry-run-planned-not-executed" },
        "manifestRawHash": { "$ref": "#/$defs/digest" },
        "selectedBatches": { "type": "integer", "minimum": 1 },
        "plannedBindings": { "type": "integer", "minimum": 1 },
        "executedBindings": { "const": 0 },
        "networkCallsMade": { "const": 0 }
      }
    },
    "proof": {
      "type": "object",
      "additionalProperties": false,
      "required": ["firstBatchEqualsManifest", "matrixEqualsCompleteManifest", "embeddedManifestRawHashesVerified", "crossStateSubstitutionAccepted"],
      "properties": {
        "firstBatchEqualsManifest": { "const": true },
        "matrixEqualsCompleteManifest": { "const": true },
        "embeddedManifestRawHashesVerified": { "const": true },
        "crossStateSubstitutionAccepted": { "const": false }
      }
    },
    "readinessState": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "counts", "manifest", "dryRuns", "proof"],
      "properties": {
        "id": { "enum": ["recovery-aware-244", "first-100-merged-335", "complete-state-336"] },
        "counts": { "$ref": "#/$defs/stateCounts" },
        "manifest": { "$ref": "#/$defs/manifest" },
        "dryRuns": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "$ref": "#/$defs/dryRun" } },
        "proof": { "$ref": "#/$defs/proof" }
      }
    },
    "executionBoundary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["sourceResolutionPerformed", "networkCodePathPresent", "approvalRequestCreated", "deploymentApprovalObtained", "productionMetricPublicationApproved", "walletWrites", "niulaiTransactions"],
      "properties": {
        "sourceResolutionPerformed": { "const": false },
        "networkCodePathPresent": { "const": false },
        "approvalRequestCreated": { "const": false },
        "deploymentApprovalObtained": { "const": false },
        "productionMetricPublicationApproved": { "const": false },
        "walletWrites": { "const": 0 },
        "niulaiTransactions": { "const": 0 }
      }
    },
    "privacy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["sourceBodiesStored", "ownerOrReviewerIdentityStored", "userOrAgentActivityStored", "requestOrResponseBodiesStored", "credentialsStored", "walletDataStored"],
      "properties": {
        "sourceBodiesStored": { "const": false },
        "ownerOrReviewerIdentityStored": { "const": false },
        "userOrAgentActivityStored": { "const": false },
        "requestOrResponseBodiesStored": { "const": false },
        "credentialsStored": { "const": false },
        "walletDataStored": { "const": false }
      }
    }
  }
}
