{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.invalid/p3/trial-record-1.0.schema.json",
  "title": "P3-R1 immutable trial record",
  "description": "Logical schema for joining a pre-setting prediction commitment, delayed setting, and post-measurement outcome. The three phases may be stored in separate append-only JSONL ledgers.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version", "run_id", "trial_id", "config_sha256",
    "prediction", "setting", "outcome"
  ],
  "properties": {
    "schema_version": {"const": "p3-trial/1.0"},
    "run_id": {"type": "string", "minLength": 8},
    "trial_id": {"type": "integer", "minimum": 0},
    "config_sha256": {"$ref": "#/$defs/sha256"},
    "prediction": {
      "type": "object",
      "additionalProperties": false,
      "required": ["predictions_by_candidate_and_setting", "prediction_sha256", "previous_prediction_sha256", "committed_unix_ns"],
      "properties": {
        "predictions_by_candidate_and_setting": {"type": "object", "minProperties": 1},
        "prediction_sha256": {"$ref": "#/$defs/sha256"},
        "previous_prediction_sha256": {"oneOf": [{"$ref": "#/$defs/sha256"}, {"type": "null"}]},
        "committed_unix_ns": {"type": "integer", "minimum": 1}
      }
    },
    "setting": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "rng_source", "generated_unix_ns", "prediction_sha256"],
      "properties": {
        "name": {"type": "string", "enum": ["Z_ALL", "X_ALL"]},
        "rng_source": {"type": "string"},
        "generated_unix_ns": {"type": "integer", "minimum": 1},
        "prediction_sha256": {"$ref": "#/$defs/sha256"}
      }
    },
    "outcome": {
      "type": "object",
      "additionalProperties": false,
      "required": ["bitstring_q2q1q0", "backend_name", "provider_job_id", "job_submitted_unix_ns", "result_retrieved_unix_ns", "setting_name"],
      "properties": {
        "bitstring_q2q1q0": {"type": "string", "pattern": "^[01]{3}$"},
        "backend_name": {"type": "string", "minLength": 1},
        "provider_job_id": {"type": "string", "minLength": 1},
        "job_submitted_unix_ns": {"type": "integer", "minimum": 1},
        "result_retrieved_unix_ns": {"type": "integer", "minimum": 1},
        "setting_name": {"type": "string", "enum": ["Z_ALL", "X_ALL"]}
      }
    }
  },
  "$defs": {
    "sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"}
  }
}
