{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://igrm.in/schemas/shock-compilation.schema.json",
  "title": "IGRM bounded shock compilation",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "object_type",
    "schema_version",
    "record_sha256",
    "release",
    "contract",
    "method",
    "scenario",
    "traversal",
    "paths",
    "assumption_ledger",
    "coverage",
    "evidence",
    "rights",
    "gaps",
    "counts",
    "result",
    "limitations"
  ],
  "properties": {
    "object_type": {"const": "shock_compilation"},
    "schema_version": {"const": "1.0.0"},
    "record_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
    "release": {"$ref": "#/$defs/releaseIdentity"},
    "contract": {"$ref": "#/$defs/contractIdentity"},
    "method": {"$ref": "#/$defs/methodIdentity"},
    "scenario": {"$ref": "#/$defs/scenarioIdentity"},
    "traversal": {"$ref": "#/$defs/traversalIdentity"},
    "paths": {
      "type": "array",
      "maxItems": 100,
      "uniqueItems": true,
      "items": {"$ref": "#/$defs/path"}
    },
    "assumption_ledger": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {"$ref": "#/$defs/assumptionLedgerRow"}
    },
    "coverage": {
      "type": "array",
      "uniqueItems": true,
      "items": {"$ref": "exposure-traversal.schema.json#/$defs/coverage"}
    },
    "evidence": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {"$ref": "exposure-traversal.schema.json#/$defs/evidenceBinding"}
    },
    "rights": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {"$ref": "exposure-traversal.schema.json#/$defs/rightsBinding"}
    },
    "gaps": {
      "type": "array",
      "uniqueItems": true,
      "items": {"$ref": "#/$defs/gap"}
    },
    "counts": {"$ref": "#/$defs/counts"},
    "result": {"$ref": "#/$defs/result"},
    "limitations": {
      "allOf": [
        {"$ref": "common.schema.json#/$defs/nonEmptyIdArray"},
        {"contains": {"const": "bounded_scenario_not_forecast"}},
        {"contains": {"const": "scenario_values_are_not_probabilities"}},
        {"contains": {"const": "structural_paths_are_not_causal_attribution"}},
        {"contains": {"const": "no_advice_or_recommendation"}},
        {"contains": {"const": "unsupported_propagation_abstains"}},
        {"contains": {"const": "requires_claim_bundle_before_non_synthetic_public_rendering"}}
      ]
    }
  },
  "$defs": {
    "releaseIdentity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "release_id",
        "record_sha256",
        "generated_at",
        "effective_date",
        "release_signer_id",
        "schema_registry_sha256",
        "method_registry_sha256",
        "rights_registry_sha256",
        "rights_signers_sha256",
        "release_signers_sha256"
      ],
      "properties": {
        "release_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "record_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "generated_at": {"$ref": "common.schema.json#/$defs/utcDateTime"},
        "effective_date": {"$ref": "common.schema.json#/$defs/date"},
        "release_signer_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "schema_registry_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "method_registry_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "rights_registry_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "rights_signers_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "release_signers_sha256": {"$ref": "common.schema.json#/$defs/sha256"}
      }
    },
    "contractIdentity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "input_schema_id",
        "input_schema_sha256",
        "output_schema_id",
        "output_schema_sha256",
        "common_schema_sha256",
        "compiler_registry_sha256",
        "exposure_traversal_schema_sha256",
        "exposure_projection_registry_sha256"
      ],
      "properties": {
        "input_schema_id": {"const": "https://igrm.in/schemas/shock-scenario.schema.json"},
        "input_schema_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "output_schema_id": {"const": "https://igrm.in/schemas/shock-compilation.schema.json"},
        "output_schema_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "common_schema_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "compiler_registry_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "exposure_traversal_schema_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "exposure_projection_registry_sha256": {"$ref": "common.schema.json#/$defs/sha256"}
      }
    },
    "methodIdentity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["method_id", "version", "implementation_sha256", "transform_ids"],
      "properties": {
        "method_id": {"const": "method:igrm.shock_compiler"},
        "version": {"const": "1.0.0"},
        "implementation_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "transform_ids": {
          "type": "array",
          "minItems": 3,
          "uniqueItems": true,
          "items": {"$ref": "common.schema.json#/$defs/stableId"}
        }
      }
    },
    "scenarioIdentity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scenario_id",
        "record_sha256",
        "created_at",
        "knowledge_cutoff",
        "event_id",
        "target_entity_id",
        "shock_subject_entity_id",
        "purpose",
        "shock",
        "substitutions",
        "buffers",
        "guardrails",
        "limitations"
      ],
      "properties": {
        "scenario_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "record_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "created_at": {"$ref": "common.schema.json#/$defs/utcDateTime"},
        "knowledge_cutoff": {"$ref": "common.schema.json#/$defs/utcDateTime"},
        "event_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "target_entity_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "shock_subject_entity_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "purpose": {"const": "bounded_stress_test"},
        "shock": {"$ref": "shock-scenario.schema.json#/$defs/shock"},
        "substitutions": {
          "type": "array",
          "maxItems": 20,
          "uniqueItems": true,
          "items": {"$ref": "shock-scenario.schema.json#/$defs/substitution"}
        },
        "buffers": {
          "type": "array",
          "maxItems": 20,
          "uniqueItems": true,
          "items": {"$ref": "shock-scenario.schema.json#/$defs/buffer"}
        },
        "guardrails": {"$ref": "shock-scenario.schema.json#/$defs/guardrails"},
        "limitations": {"$ref": "shock-scenario.schema.json#/properties/limitations"}
      }
    },
    "traversalIdentity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["record_sha256", "method_id", "method_version", "selection_rule", "max_hops", "max_paths", "truncated"],
      "properties": {
        "record_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "method_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "method_version": {"$ref": "common.schema.json#/$defs/schemaVersion"},
        "selection_rule": {"type": "string", "minLength": 1, "maxLength": 160},
        "max_hops": {"type": "integer", "minimum": 1, "maximum": 6},
        "max_paths": {"type": "integer", "minimum": 1, "maximum": 100},
        "truncated": {"type": "boolean"}
      }
    },
    "interval": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lower", "upper", "unit"],
      "properties": {
        "lower": {"type": "number", "minimum": 0},
        "upper": {"type": "number", "minimum": 0},
        "unit": {"type": "string", "minLength": 1, "maxLength": 120}
      }
    },
    "boundedMeasure": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lower", "upper", "unit", "denominator", "equation", "transform_id"],
      "properties": {
        "lower": {"type": "number", "minimum": 0},
        "upper": {"type": "number", "minimum": 0},
        "unit": {"const": "percentage_points_of_edge_denominator"},
        "denominator": {"type": "string", "minLength": 1, "maxLength": 300},
        "equation": {"type": "string", "minLength": 1, "maxLength": 300},
        "transform_id": {"$ref": "common.schema.json#/$defs/stableId"}
      }
    },
    "durationMeasure": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lower", "upper", "unit", "equation", "transform_id"],
      "properties": {
        "lower": {"type": "integer", "minimum": 0},
        "upper": {"type": "integer", "minimum": 0},
        "unit": {"const": "days"},
        "equation": {"type": "string", "minLength": 1, "maxLength": 300},
        "transform_id": {"$ref": "common.schema.json#/$defs/stableId"}
      }
    },
    "freshness": {
      "type": "object",
      "additionalProperties": false,
      "required": ["observed_at", "observation_age_seconds", "max_current_age_days", "status", "source_policies"],
      "properties": {
        "observed_at": {"$ref": "common.schema.json#/$defs/utcDateTime"},
        "observation_age_seconds": {"type": "integer", "minimum": 0},
        "max_current_age_days": {"type": ["integer", "null"], "minimum": 1},
        "status": {"enum": ["current", "stale", "unknown_policy"]},
        "source_policies": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["source_id", "max_current_age_days"],
            "properties": {
              "source_id": {"$ref": "common.schema.json#/$defs/stableId"},
              "max_current_age_days": {"type": ["integer", "null"], "minimum": 1}
            }
          }
        }
      }
    },
    "hop": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "edge_id",
        "record_sha256",
        "source_entity_id",
        "target_entity_id",
        "edge_type",
        "quantification_status",
        "magnitude",
        "freshness",
        "coverage",
        "evidence_ids",
        "limitation_codes"
      ],
      "properties": {
        "edge_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "record_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "source_entity_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "target_entity_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "edge_type": {"type": "string", "minLength": 1, "maxLength": 120},
        "quantification_status": {"enum": ["quantified", "qualitative", "unknown"]},
        "magnitude": {"oneOf": [{"$ref": "common.schema.json#/$defs/measure"}, {"type": "null"}]},
        "freshness": {"$ref": "#/$defs/freshness"},
        "coverage": {"$ref": "exposure-traversal.schema.json#/$defs/coverage"},
        "evidence_ids": {"$ref": "common.schema.json#/$defs/nonEmptyIdArray"},
        "limitation_codes": {"$ref": "common.schema.json#/$defs/idArray"}
      }
    },
    "sensitivityCell": {
      "type": "object",
      "additionalProperties": false,
      "required": ["shock_magnitude_percent", "duration_days", "gross_affected_share", "residual_affected_share", "residual_duration_days"],
      "properties": {
        "shock_magnitude_percent": {"type": "number", "minimum": 0, "maximum": 100},
        "duration_days": {"type": "integer", "minimum": 1},
        "gross_affected_share": {"$ref": "#/$defs/boundedMeasure"},
        "residual_affected_share": {"$ref": "#/$defs/boundedMeasure"},
        "residual_duration_days": {"$ref": "#/$defs/durationMeasure"}
      }
    },
    "path": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "path_id",
        "entry_entity_id",
        "entity_ids",
        "edge_ids",
        "hops",
        "quantification_status",
        "reason_code",
        "gross_affected_share",
        "residual_affected_share",
        "residual_duration",
        "sensitivity_grid",
        "assumption_ids_used",
        "gap_codes",
        "limitation_codes"
      ],
      "properties": {
        "path_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "entry_entity_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "entity_ids": {"$ref": "common.schema.json#/$defs/nonEmptyIdArray"},
        "edge_ids": {"$ref": "common.schema.json#/$defs/nonEmptyIdArray"},
        "hops": {"type": "array", "minItems": 1, "maxItems": 6, "items": {"$ref": "#/$defs/hop"}},
        "quantification_status": {"enum": ["bounded_range", "abstained"]},
        "reason_code": {"$ref": "common.schema.json#/$defs/stableId"},
        "gross_affected_share": {"oneOf": [{"$ref": "#/$defs/boundedMeasure"}, {"type": "null"}]},
        "residual_affected_share": {"oneOf": [{"$ref": "#/$defs/boundedMeasure"}, {"type": "null"}]},
        "residual_duration": {"oneOf": [{"$ref": "#/$defs/durationMeasure"}, {"type": "null"}]},
        "sensitivity_grid": {"type": "array", "maxItems": 4, "items": {"$ref": "#/$defs/sensitivityCell"}},
        "assumption_ids_used": {"$ref": "common.schema.json#/$defs/idArray"},
        "gap_codes": {"$ref": "common.schema.json#/$defs/idArray"},
        "limitation_codes": {"$ref": "common.schema.json#/$defs/idArray"}
      }
    },
    "assumptionLedgerRow": {
      "type": "object",
      "additionalProperties": false,
      "required": ["assumption_id", "assumption_type", "status", "origin", "used_by_path_ids", "unused_reason"],
      "properties": {
        "assumption_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "assumption_type": {"enum": ["shock", "substitution", "buffer"]},
        "status": {"const": "hypothetical"},
        "origin": {"const": "user_supplied"},
        "used_by_path_ids": {"$ref": "common.schema.json#/$defs/idArray"},
        "unused_reason": {"oneOf": [{"$ref": "common.schema.json#/$defs/stableId"}, {"type": "null"}]}
      }
    },
    "gap": {
      "type": "object",
      "additionalProperties": false,
      "required": ["gap_id", "gap_code", "path_id", "edge_id", "assumption_id"],
      "properties": {
        "gap_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "gap_code": {"$ref": "common.schema.json#/$defs/stableId"},
        "path_id": {"oneOf": [{"$ref": "common.schema.json#/$defs/stableId"}, {"type": "null"}]},
        "edge_id": {"oneOf": [{"$ref": "common.schema.json#/$defs/stableId"}, {"type": "null"}]},
        "assumption_id": {"oneOf": [{"$ref": "common.schema.json#/$defs/stableId"}, {"type": "null"}]}
      }
    },
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["structural_paths", "bounded_paths", "abstained_paths", "stale_hops", "unknown_freshness_hops", "gaps", "assumptions", "assumptions_used"],
      "properties": {
        "structural_paths": {"type": "integer", "minimum": 0},
        "bounded_paths": {"type": "integer", "minimum": 0},
        "abstained_paths": {"type": "integer", "minimum": 0},
        "stale_hops": {"type": "integer", "minimum": 0},
        "unknown_freshness_hops": {"type": "integer", "minimum": 0},
        "gaps": {"type": "integer", "minimum": 0},
        "assumptions": {"type": "integer", "minimum": 1},
        "assumptions_used": {"type": "integer", "minimum": 0}
      }
    },
    "result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "public_claim_state",
        "forecast_performed",
        "probability_assigned",
        "causal_attribution_performed",
        "recommendation_generated",
        "scalar_score_computed"
      ],
      "properties": {
        "status": {"enum": ["compiled", "partially_compiled", "structural_only", "no_path"]},
        "public_claim_state": {"const": "requires_claim_bundle"},
        "forecast_performed": {"const": false},
        "probability_assigned": {"const": false},
        "causal_attribution_performed": {"const": false},
        "recommendation_generated": {"const": false},
        "scalar_score_computed": {"const": false}
      }
    }
  }
}
