{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.osoix.com/rbp-1.schema.json",
  "title": "OSOIX Reality Boundary Protocol v1 Capsule",
  "description": "Machine-readable reality, provenance, derivation, uncertainty and authority boundaries for an OSOIX evidence capsule.",
  "type": "object",
  "required": [
    "protocol",
    "profile",
    "capsuleId",
    "subject",
    "generatedAt",
    "evaluatedAt",
    "horizonHours",
    "sources",
    "claims",
    "contradictions",
    "counterfactuals",
    "boundaries",
    "prov",
    "digest",
    "validation"
  ],
  "properties": {
    "protocol": { "const": "osoix.rbp.v1" },
    "profile": { "type": "string", "minLength": 1 },
    "capsuleId": { "type": "string", "minLength": 1 },
    "subject": {
      "type": "object",
      "required": ["type", "noradId", "name"],
      "properties": {
        "type": { "const": "orbital-object" },
        "noradId": { "type": "string", "pattern": "^[0-9]{1,8}$" },
        "name": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "generatedAt": { "type": "string", "format": "date-time" },
    "evaluatedAt": { "type": "string", "format": "date-time" },
    "horizonHours": { "type": "number", "minimum": 0, "maximum": 72 },
    "sources": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/source" }
    },
    "claims": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/claim" }
    },
    "contradictions": {
      "type": "array",
      "items": { "$ref": "#/$defs/contradiction" }
    },
    "counterfactuals": {
      "type": "array",
      "items": { "$ref": "#/$defs/counterfactual" }
    },
    "boundaries": { "$ref": "#/$defs/boundaries" },
    "prov": {
      "type": "object",
      "required": ["@context", "@graph"],
      "properties": {
        "@context": { "type": "object" },
        "@graph": { "type": "array" }
      },
      "additionalProperties": true
    },
    "digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "validation": { "$ref": "#/$defs/validation" }
  },
  "$defs": {
    "nullableDateTime": {
      "oneOf": [
        { "type": "string", "format": "date-time" },
        { "type": "null" }
      ]
    },
    "source": {
      "type": "object",
      "required": ["id", "label", "status", "fetchedAt", "sourceEpoch", "recordDigest", "warning"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "label": { "type": "string", "minLength": 1 },
        "status": {
          "enum": ["available", "degraded", "unavailable", "unconfigured", "not-returned"]
        },
        "fetchedAt": { "type": "string", "format": "date-time" },
        "sourceEpoch": { "$ref": "#/$defs/nullableDateTime" },
        "recordDigest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "warning": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "claim": {
      "type": "object",
      "required": [
        "id",
        "subject",
        "label",
        "statement",
        "realityClass",
        "value",
        "unit",
        "sources",
        "dependencies",
        "transformations",
        "temporalBasis",
        "uncertainty",
        "authority",
        "digest"
      ],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "subject": { "type": "string", "minLength": 1 },
        "label": { "type": "string", "minLength": 1 },
        "statement": { "type": "string", "minLength": 1 },
        "realityClass": {
          "enum": ["OBSERVED", "REPORTED", "CALCULATED", "PROJECTED", "INFERRED", "SYNTHETIC", "UNKNOWN"]
        },
        "value": {},
        "unit": { "type": ["string", "null"] },
        "sources": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "dependencies": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "transformations": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["id", "label", "version"],
            "properties": {
              "id": { "type": "string", "minLength": 1 },
              "label": { "type": "string", "minLength": 1 },
              "version": { "type": "string", "minLength": 1 },
              "frame": { "type": "string", "minLength": 1 }
            },
            "additionalProperties": false
          }
        },
        "temporalBasis": {
          "type": "object",
          "required": ["sourceEpoch", "evaluatedAt", "horizonSeconds"],
          "properties": {
            "sourceEpoch": { "$ref": "#/$defs/nullableDateTime" },
            "evaluatedAt": { "type": "string", "format": "date-time" },
            "horizonSeconds": { "type": "number", "minimum": 0, "maximum": 259200 }
          },
          "additionalProperties": false
        },
        "uncertainty": {
          "type": "object",
          "required": ["mode", "covarianceIncluded", "statement"],
          "properties": {
            "mode": { "enum": ["formal", "proxy", "unavailable"] },
            "covarianceIncluded": { "type": "boolean" },
            "statement": { "type": "string", "minLength": 1 }
          },
          "additionalProperties": false
        },
        "authority": {
          "type": "object",
          "required": ["level", "commandPath"],
          "properties": {
            "level": { "enum": ["none", "research", "advisory", "operational"] },
            "commandPath": { "const": false }
          },
          "additionalProperties": false
        },
        "digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
      },
      "additionalProperties": false
    },
    "contradiction": {
      "type": "object",
      "required": [
        "id",
        "claimIds",
        "status",
        "positionDeltaKm",
        "altitudeDeltaKm",
        "velocityDeltaKmS",
        "epochSeparationMinutes",
        "deltaBand",
        "statement"
      ],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "claimIds": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "status": { "enum": ["NOT_EVALUATED", "SINGLE_SOURCE", "CROSS_SOURCE_DELTA"] },
        "positionDeltaKm": { "type": ["number", "null"], "minimum": 0 },
        "altitudeDeltaKm": { "type": ["number", "null"], "minimum": 0 },
        "velocityDeltaKmS": { "type": ["number", "null"], "minimum": 0 },
        "epochSeparationMinutes": { "type": ["number", "null"], "minimum": 0 },
        "deltaBand": { "enum": ["NOT_AVAILABLE", "LT_5_KM", "5_TO_25_KM", "GE_25_KM"] },
        "statement": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "counterfactual": {
      "type": "object",
      "required": [
        "id",
        "removedSources",
        "survivingClaimIds",
        "invalidatedClaimIds",
        "survivalRatio",
        "currentStateAvailable",
        "futureProjectionAvailable",
        "statement"
      ],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "removedSources": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "survivingClaimIds": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "invalidatedClaimIds": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "survivalRatio": { "type": "number", "minimum": 0, "maximum": 1 },
        "currentStateAvailable": { "type": "boolean" },
        "futureProjectionAvailable": { "type": "boolean" },
        "statement": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "boundaries": {
      "type": "object",
      "required": [
        "directObservationIncluded",
        "formalCovarianceIncluded",
        "collisionProbabilityCalculated",
        "spacecraftTelemetryClaimed",
        "commandPath",
        "uplink",
        "transmission",
        "scheduling"
      ],
      "properties": {
        "directObservationIncluded": { "type": "boolean" },
        "formalCovarianceIncluded": { "type": "boolean" },
        "collisionProbabilityCalculated": { "type": "boolean" },
        "spacecraftTelemetryClaimed": { "type": "boolean" },
        "commandPath": { "const": false },
        "uplink": { "const": false },
        "transmission": { "const": false },
        "scheduling": { "const": false }
      },
      "additionalProperties": false
    },
    "validation": {
      "type": "object",
      "required": ["valid", "errors", "warnings", "checkedAt"],
      "properties": {
        "valid": { "type": "boolean" },
        "errors": { "type": "array", "items": { "type": "string" } },
        "warnings": { "type": "array", "items": { "type": "string" } },
        "checkedAt": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
