{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://lab.parkneural.com/gaterestart/data/v3/report-schema.json",
  "title": "GateRestart AI V3 synthetic event report",
  "description": "12 fictional situations. Waveform features are computed from CSV; injected source identities are explicitly identified as simulator assumptions; not a real vehicle diagnostic result.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "report_schema_version", "analysis_version", "report_id", "scenario", "synthetic",
    "synthetic_label", "unit", "time_unit", "provenance", "selection",
    "assumptions_from_synthetic_generator", "features_computed_from_csv",
    "decision", "narrative", "cannot_infer"
  ],
  "properties": {
    "report_schema_version": {"const": "3.0.0"},
    "analysis_version": {"const": "gr-edge-synthetic-3.0.0"},
    "report_id": {"type": "string", "pattern": "^GRV3-SIM-(0[1-9]|1[0-2])$"},
    "scenario": {
      "type": "object",
      "required": ["id", "title", "subtitle", "page_path", "fictional_site"],
      "properties": {
        "id": {"type": "string", "pattern": "^SIM-(0[1-9]|1[0-2])$"},
        "title": {"type": "string"}, "subtitle": {"type": "string"},
        "page_path": {"type": "string", "pattern": "^/gaterestart/simulations/.+/$"},
        "fictional_site": {"type": "string"}
      }
    },
    "synthetic": {"const": true},
    "synthetic_label": {"type": "string", "minLength": 2},
    "unit": {"const": "a.u."}, "time_unit": {"const": "s"},
    "provenance": {
      "type": "object",
      "required": ["csv_path", "csv_sha256", "cases_path", "cases_sha256", "manifest_path", "manifest_sha256", "generator_path", "generator_version", "data_version", "case_seed", "hash_verified_on_load"],
      "properties": {
        "csv_path": {"const": "data/v3/synthetic_events_v3.csv"},
        "csv_sha256": {"$ref": "#/$defs/hash"},
        "cases_path": {"const": "data/v3/cases_v3.json"},
        "cases_sha256": {"$ref": "#/$defs/hash"},
        "manifest_path": {"const": "data/v3/data-manifest.json"},
        "manifest_sha256": {"$ref": "#/$defs/hash"},
        "generator_path": {"const": "simulation_v3/generate_v3.py"},
        "generator_version": {"const": "3.0.0"},
        "data_version": {"const": "grv3-synthetic-20261114-r1"},
        "case_seed": {"type": "integer", "minimum": 101, "maximum": 112},
        "hash_verified_on_load": {"const": true}
      }
    },
    "selection": {
      "type": "object",
      "required": ["start_s", "end_s", "bounds_inclusive", "source_samples_per_case", "selected_samples"],
      "properties": {
        "start_s": {"type": "number"}, "end_s": {"type": "number"},
        "bounds_inclusive": {"const": true},
        "source_samples_per_case": {"const": 601},
        "selected_samples": {"type": "integer", "minimum": 0, "maximum": 601}
      }
    },
    "assumptions_from_synthetic_generator": {
      "type": "object",
      "required": ["source_types_injected", "target_restart_injected", "injected_component_names", "timebase_status", "gate_marker_s", "simulated_gate_clock_late_by_s", "reference_loss_window_s", "clip_limit_au", "source_attribution_is_generator_assumption_not_waveform_inference"],
      "properties": {
        "source_types_injected": {"type": "array", "items": {"type": "string"}},
        "target_restart_injected": {"type": "boolean"},
        "injected_component_names": {"type": "array", "items": {"type": "string"}},
        "timebase_status": {"enum": ["NOMINAL", "OFFSET_UNCERTAIN"]},
        "gate_marker_s": {"const": 0},
        "simulated_gate_clock_late_by_s": {"type": ["number", "null"]},
        "reference_loss_window_s": {"oneOf": [{"type": "null"}, {"type": "array", "minItems": 2, "maxItems": 2, "items": {"type": "number"}}]},
        "clip_limit_au": {"type": "object", "additionalProperties": {"type": "number"}},
        "source_attribution_is_generator_assumption_not_waveform_inference": {"const": true}
      }
    },
    "features_computed_from_csv": {
      "type": "object",
      "required": ["calculation_scope", "baseline_window_s", "tail_drift_compare_windows_s", "coverage", "baseline_by_channel_au", "peak_by_channel", "max_abs_adjacent_slope_au_per_s", "end_minus_start_median_au", "reference_similarity", "bx_candidate_peaks", "reference_difference"],
      "properties": {
        "calculation_scope": {"type": "string"},
        "baseline_window_s": {"$ref": "#/$defs/interval"},
        "tail_drift_compare_windows_s": {"type": "array", "minItems": 2, "maxItems": 2, "items": {"$ref": "#/$defs/interval"}},
        "coverage": {"$ref": "#/$defs/channelCoverage"},
        "baseline_by_channel_au": {"$ref": "#/$defs/channelNullNumber"},
        "peak_by_channel": {
          "type": "object", "required": ["bx", "by", "bz", "reference"],
          "properties": {"bx": {"$ref": "#/$defs/nullablePeak"}, "by": {"$ref": "#/$defs/nullablePeak"}, "bz": {"$ref": "#/$defs/nullablePeak"}, "reference": {"$ref": "#/$defs/nullablePeak"}}
        },
        "max_abs_adjacent_slope_au_per_s": {"$ref": "#/$defs/channelNullNumber"},
        "end_minus_start_median_au": {"$ref": "#/$defs/channelNullNumber"},
        "reference_similarity": {
          "type": "object",
          "required": ["method", "comparison_window_s", "valid_pairs", "pearson_r", "reference_peak_abs_deviation_au"],
          "properties": {
            "method": {"type": "string"},
            "comparison_window_s": {"$ref": "#/$defs/interval"},
            "valid_pairs": {"type": "integer", "minimum": 0},
            "pearson_r": {"type": ["number", "null"], "minimum": -1, "maximum": 1},
            "reference_peak_abs_deviation_au": {"type": ["number", "null"]}
          }
        },
        "bx_candidate_peaks": {
          "type": "object",
          "required": ["method", "threshold_au", "peaks", "first_two_gap_s"],
          "properties": {
            "method": {"type": "string"},
            "threshold_au": {"const": 0.12},
            "peaks": {"type": "array", "items": {"type": "object", "required": ["time_s", "height_above_baseline_au"], "properties": {"time_s": {"type": "number"}, "height_above_baseline_au": {"type": "number"}}}},
            "first_two_gap_s": {"type": ["number", "null"]}
          }
        },
        "reference_difference": {
          "type": "object",
          "required": ["method", "coefficient", "valid_pairs", "baseline_au", "maximum_abs_deviation_au", "time_of_max_s"],
          "properties": {
            "method": {"type": "string"}, "coefficient": {"const": 1},
            "valid_pairs": {"type": "integer", "minimum": 0},
            "baseline_au": {"type": ["number", "null"]},
            "maximum_abs_deviation_au": {"type": ["number", "null"]},
            "time_of_max_s": {"type": ["number", "null"]}
          }
        }
      }
    },
    "decision": {
      "type": "object",
      "required": ["status", "label", "label_zh", "reasons", "logic_version", "is_trained_diagnostic_model", "real_vehicle_health", "diagnostic_confidence", "quality_state", "reasoning_is_synthetic_rule_based"],
      "properties": {
        "status": {"enum": ["RENDER_EVENT", "ABSTAIN"]},
        "label": {"enum": ["REFERENCE_PATTERN", "EXTRA_PULSE", "GATE_MOTOR_INTERFERENCE", "MULTI_SOURCE", "NO_RESTART", "DELAYED_PULSE", "MOTION_ARTIFACT", "BASELINE_DRIFT", "SENSOR_SATURATED", "NON_VEHICLE_SOURCE", "SYNC_UNCERTAIN", "REFERENCE_LOST", "INSUFFICIENT_WINDOW", "INSUFFICIENT_EVIDENCE", "METADATA_SIGNAL_CONFLICT"]},
        "label_zh": {"type": "string"},
        "reasons": {"type": "array", "minItems": 1, "items": {"type": "object", "required": ["basis", "note", "detail"], "properties": {"basis": {"enum": ["computed_feature", "csv_status", "scenario_assumption", "combined"]}, "note": {"type": "string"}, "detail": {}}}},
        "logic_version": {"const": "gr-edge-synthetic-3.0.0"},
        "is_trained_diagnostic_model": {"const": false},
        "real_vehicle_health": {"const": null},
        "diagnostic_confidence": {"const": null},
        "quality_state": {"enum": ["ABSTAIN", "DEMO_PASS"]},
        "reasoning_is_synthetic_rule_based": {"const": true}
      }
    },
    "narrative": {
      "type": "object", "required": ["context", "result", "lesson", "evidence_note"],
      "properties": {"context": {"type": "string"}, "result": {"type": "string"}, "lesson": {"type": "string"}, "evidence_note": {"type": "string"}}
    },
    "cannot_infer": {"type": "array", "minItems": 4, "items": {"type": "string"}}
  },
  "$defs": {
    "hash": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
    "interval": {"type": "array", "minItems": 2, "maxItems": 2, "items": {"type": "number"}},
    "channelNullNumber": {
      "type": "object", "required": ["bx", "by", "bz", "reference"],
      "properties": {
        "bx": {"type": ["number", "null"]}, "by": {"type": ["number", "null"]},
        "bz": {"type": ["number", "null"]}, "reference": {"type": ["number", "null"]}
      }
    },
    "channelCoverage": {
      "type": "object", "required": ["bx", "by", "bz", "reference"],
      "properties": {
        "bx": {"$ref": "#/$defs/counts"}, "by": {"$ref": "#/$defs/counts"},
        "bz": {"$ref": "#/$defs/counts"}, "reference": {"$ref": "#/$defs/counts"}
      }
    },
    "counts": {
      "type": "object", "required": ["total", "valid", "saturated", "lost", "valid_fraction"],
      "properties": {
        "total": {"type": "integer", "minimum": 0},
        "valid": {"type": "integer", "minimum": 0},
        "saturated": {"type": "integer", "minimum": 0},
        "lost": {"type": "integer", "minimum": 0},
        "valid_fraction": {"type": ["number", "null"], "minimum": 0, "maximum": 1}
      }
    },
    "nullablePeak": {
      "oneOf": [
        {"type": "null"},
        {"type": "object", "required": ["absolute_deviation_au", "absolute_deviation_time_s", "signed_deviation_au", "maximum_au", "maximum_time_s", "minimum_au", "minimum_time_s"],
          "properties": {
            "absolute_deviation_au": {"type": "number"},
            "absolute_deviation_time_s": {"type": "number"},
            "signed_deviation_au": {"type": "number"},
            "maximum_au": {"type": "number"}, "maximum_time_s": {"type": "number"},
            "minimum_au": {"type": "number"}, "minimum_time_s": {"type": "number"}
          }}
      ]
    }
  }
}
