{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kaldenframelabs.com/schemas/clock-interpretation-probe-report-v1.schema.json",
  "title": "KaldenFrame Clock Interpretation Probe Report v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema", "probe_id", "tool", "contract_sha256", "classification",
    "top_ranked_interpretation_id", "top_coverage_basis_points",
    "runner_up_interpretation_id", "coverage_gap_basis_points", "thresholds",
    "reference", "candidate", "inputs", "interpretations", "input_policy", "limitations"
  ],
  "properties": {
    "schema": { "const": "kaldenframe.clock-interpretation-probe-report.v1" },
    "probe_id": { "$ref": "#/$defs/identifier" },
    "tool": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version"],
      "properties": {
        "name": { "const": "KaldenFrame Temporal Boundary Auditor" },
        "version": { "type": "string" }
      }
    },
    "contract_sha256": { "type": "string", "pattern": "^[A-F0-9]{64}$" },
    "classification": { "enum": ["DOMINANT", "AMBIGUOUS", "INSUFFICIENT_COVERAGE", "REFERENCE_INVALID"] },
    "top_ranked_interpretation_id": { "$ref": "#/$defs/identifier" },
    "top_coverage_basis_points": { "$ref": "#/$defs/basisPoints" },
    "runner_up_interpretation_id": { "$ref": "#/$defs/identifier" },
    "coverage_gap_basis_points": { "$ref": "#/$defs/basisPoints" },
    "thresholds": {
      "type": "object",
      "additionalProperties": false,
      "required": ["minimum_coverage_basis_points", "minimum_gap_basis_points", "tolerance_seconds", "direction"],
      "properties": {
        "minimum_coverage_basis_points": { "$ref": "#/$defs/basisPoints" },
        "minimum_gap_basis_points": { "type": "integer", "minimum": 1, "maximum": 10000 },
        "tolerance_seconds": { "type": "integer", "minimum": 0, "maximum": 31536000 },
        "direction": { "const": "BACKWARD" }
      }
    },
    "reference": { "$ref": "#/$defs/datasetSummary" },
    "candidate": { "$ref": "#/$defs/candidateSummary" },
    "inputs": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "$ref": "#/$defs/input" } },
    "interpretations": { "type": "array", "minItems": 2, "maxItems": 64, "items": { "$ref": "#/$defs/result" } },
    "input_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source_files_mutated", "row_values_copied_to_report", "source_paths_copied_to_report", "candidate_interpretations_are_caller_declared"],
      "properties": {
        "source_files_mutated": { "const": false },
        "row_values_copied_to_report": { "const": false },
        "source_paths_copied_to_report": { "const": false },
        "candidate_interpretations_are_caller_declared": { "const": true }
      }
    },
    "limitations": { "type": "array", "minItems": 5, "items": { "type": "string", "minLength": 1 } }
  },
  "$defs": {
    "identifier": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{0,63}$" },
    "basisPoints": { "type": "integer", "minimum": 0, "maximum": 10000 },
    "count": { "type": "integer", "minimum": 0 },
    "nullableInteger": { "type": ["integer", "null"] },
    "datasetSummary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["dataset_id", "row_count", "unique_valid_timestamp_count", "invalid_timestamp_count"],
      "properties": {
        "dataset_id": { "$ref": "#/$defs/identifier" },
        "row_count": { "$ref": "#/$defs/count" },
        "unique_valid_timestamp_count": { "$ref": "#/$defs/count" },
        "invalid_timestamp_count": { "$ref": "#/$defs/count" }
      }
    },
    "candidateSummary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["dataset_id", "row_count", "unique_raw_timestamp_count"],
      "properties": {
        "dataset_id": { "$ref": "#/$defs/identifier" },
        "row_count": { "$ref": "#/$defs/count" },
        "unique_raw_timestamp_count": { "$ref": "#/$defs/count" }
      }
    },
    "input": {
      "type": "object",
      "additionalProperties": false,
      "required": ["dataset_id", "format", "sha256", "byte_count", "row_count", "columns"],
      "properties": {
        "dataset_id": { "$ref": "#/$defs/identifier" },
        "format": { "enum": ["csv", "jsonl"] },
        "sha256": { "type": "string", "pattern": "^[A-F0-9]{64}$" },
        "byte_count": { "$ref": "#/$defs/count" },
        "row_count": { "$ref": "#/$defs/count" },
        "columns": { "type": "array", "items": { "type": "string" }, "uniqueItems": true }
      }
    },
    "result": {
      "type": "object",
      "required": [
        "interpretation_id", "mode", "candidate_unique_raw_timestamp_count", "parsed_timestamp_count",
        "invalid_format_count", "ambiguous_local_time_count", "nonexistent_local_time_count",
        "entity_count_with_reference", "entity_count_without_reference", "backward_match_count",
        "exact_match_count", "coverage_basis_points", "minimum_lag_milliseconds",
        "maximum_lag_milliseconds", "rank"
      ],
      "properties": {
        "interpretation_id": { "$ref": "#/$defs/identifier" },
        "mode": { "enum": ["EXPLICIT_RFC3339", "NAIVE_FIXED_OFFSET", "NAIVE_IANA_ZONE"] },
        "offset_minutes": { "type": "integer", "minimum": -840, "maximum": 840 },
        "zone": { "type": "string", "minLength": 1, "maxLength": 128 },
        "candidate_unique_raw_timestamp_count": { "$ref": "#/$defs/count" },
        "parsed_timestamp_count": { "$ref": "#/$defs/count" },
        "invalid_format_count": { "$ref": "#/$defs/count" },
        "ambiguous_local_time_count": { "$ref": "#/$defs/count" },
        "nonexistent_local_time_count": { "$ref": "#/$defs/count" },
        "entity_count_with_reference": { "$ref": "#/$defs/count" },
        "entity_count_without_reference": { "$ref": "#/$defs/count" },
        "backward_match_count": { "$ref": "#/$defs/count" },
        "exact_match_count": { "$ref": "#/$defs/count" },
        "coverage_basis_points": { "$ref": "#/$defs/basisPoints" },
        "minimum_lag_milliseconds": { "$ref": "#/$defs/nullableInteger" },
        "maximum_lag_milliseconds": { "$ref": "#/$defs/nullableInteger" },
        "rank": { "type": "integer", "minimum": 1, "maximum": 64 }
      },
      "additionalProperties": false
    }
  }
}
