{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hsimc.tech/rd/t736/ecosystem/schemas/observation.schema.json",
  "title": "Case reference: source-linked observation",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "observation_id",
    "source_kind",
    "runtime_ref",
    "captured_at",
    "time_uncertainty_ms",
    "modality",
    "original",
    "access",
    "transformations",
    "facts"
  ],
  "properties": {
    "schema_version": {
      "const": "C0-001"
    },
    "observation_id": {
      "type": "string",
      "minLength": 1
    },
    "source_kind": {
      "enum": [
        "SIMULATED",
        "REPLAY",
        "PHYSICAL",
        "HUMAN_STUDY"
      ]
    },
    "runtime_ref": {
      "type": "string",
      "minLength": 1
    },
    "captured_at": {
      "type": "string",
      "format": "date-time"
    },
    "time_uncertainty_ms": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0
    },
    "modality": {
      "enum": [
        "text",
        "image",
        "audio",
        "measurement",
        "multimodal"
      ]
    },
    "original": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "locator",
        "sha256",
        "media_type"
      ],
      "properties": {
        "locator": {
          "type": "string",
          "minLength": 1
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "media_type": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "access": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scope_ref",
        "retention_policy_ref"
      ],
      "properties": {
        "scope_ref": {
          "type": "string",
          "minLength": 1
        },
        "retention_policy_ref": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "transformations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "method",
          "version",
          "parent_sha256"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "method": {
            "type": "string",
            "minLength": 1
          },
          "version": {
            "type": "string",
            "minLength": 1
          },
          "parent_sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "output_sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        }
      }
    },
    "facts": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "key",
          "value",
          "unit",
          "coordinate_frame",
          "confidence"
        ],
        "properties": {
          "key": {
            "type": "string",
            "minLength": 1
          },
          "value": {},
          "unit": {
            "type": [
              "string",
              "null"
            ]
          },
          "coordinate_frame": {
            "type": [
              "string",
              "null"
            ]
          },
          "confidence": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 1
          }
        }
      }
    }
  }
}
