{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://tsep-protocol.org/assets/schemas/google-update-family.schema.json",
  "title": "TSEP Google update family export, schema version 2",
  "description": "Retained documentary evidence. Date-only boundaries must not be interpreted as midnight instants. Additional fields support backwards-compatible enrichment.",
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string",
      "format": "uri"
    },
    "schema_version": {
      "const": 2
    },
    "id": {
      "type": "string"
    },
    "rows": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/row"
      }
    },
    "calendar_timezone": {
      "enum": [
        "US/Pacific",
        "America/Los_Angeles"
      ]
    },
    "data_version": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}\\.[a-f0-9]{12}$"
    },
    "family": {
      "enum": [
        "core",
        "spam",
        "reviews",
        "helpful",
        "discover",
        "experience"
      ]
    },
    "language": {
      "enum": [
        "fr",
        "en"
      ]
    },
    "editorial_revision": {
      "type": "string"
    },
    "version": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "row_count": {
      "type": "integer",
      "minimum": 0
    },
    "references": {
      "type": "object"
    },
    "editorial_review": {
      "type": "object",
      "properties": {
        "state": {
          "enum": [
            "pending",
            "reviewed",
            "stale"
          ]
        },
        "assistance": {
          "type": "string"
        }
      },
      "required": [
        "state"
      ],
      "additionalProperties": true
    },
    "history_observation": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "source": {
          "$ref": "#/definitions/proof"
        },
        "visible_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z0-9]+$"
          },
          "uniqueItems": true
        },
        "visible_count": {
          "type": "integer",
          "minimum": 0
        },
        "date_semantics": {
          "type": "string"
        },
        "timestamp_scope": {
          "type": "string"
        }
      },
      "required": [
        "source",
        "visible_ids",
        "visible_count",
        "date_semantics",
        "timestamp_scope"
      ],
      "additionalProperties": true
    },
    "primary_statistic": {
      "type": "object",
      "description": "Primary headline benchmark; other precision and historical populations remain separately available.",
      "required": [
        "measure",
        "value",
        "unit",
        "population_count",
        "population",
        "timezone",
        "method"
      ],
      "properties": {
        "measure": {
          "const": "median_rollout_duration"
        },
        "value": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "unit": {
          "const": "calendar_day"
        },
        "population_count": {
          "type": "integer",
          "minimum": 0
        },
        "population": {
          "const": "completed_dashboard_core_rollouts"
        },
        "timezone": {
          "const": "America/Los_Angeles"
        },
        "method": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "monitor": {
      "type": "object",
      "description": "Recorded checks and verified captures. A recommended next due time is not an active scheduler or a guaranteed publication time.",
      "properties": {
        "status": {
          "type": "string"
        },
        "last_attempt_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "last_success_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "automation_enabled": {
          "type": "boolean"
        }
      },
      "required": [
        "status",
        "last_attempt_at",
        "last_success_at",
        "automation_enabled"
      ],
      "additionalProperties": true
    },
    "history_observations": {
      "type": "object",
      "description": "Retained Ranking list observations, independently replayed from captured bytes; explanatory hypotheses remain separate.",
      "required": [
        "observations",
        "interpretation",
        "limits"
      ],
      "additionalProperties": true
    }
  },
  "required": [
    "$schema",
    "schema_version",
    "id",
    "rows",
    "calendar_timezone",
    "data_version",
    "family",
    "language",
    "editorial_revision",
    "version",
    "row_count",
    "references",
    "editorial_review"
  ],
  "additionalProperties": true,
  "definitions": {
    "proof": {
      "type": "object",
      "properties": {
        "url": {
          "type": "string",
          "format": "uri"
        },
        "sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "capture": {
          "type": "string",
          "pattern": "^/(assets/watch-(ranking|impact)/|veille/captures/)[a-f0-9]{64}\\.gz$"
        },
        "observed": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "url",
        "sha256",
        "capture",
        "observed"
      ],
      "additionalProperties": true
    },
    "row": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9]+$"
        },
        "title": {
          "type": "string"
        },
        "start": {
          "type": "string"
        },
        "end": {
          "type": [
            "string",
            "null"
          ]
        },
        "start_precision": {
          "enum": [
            "day",
            "minute"
          ]
        },
        "end_precision": {
          "enum": [
            "day",
            "minute",
            null
          ]
        },
        "source_start": {
          "type": "string"
        },
        "source_end": {
          "type": [
            "string",
            "null"
          ]
        },
        "duration_minutes": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "calendar_days": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "status": {
          "enum": [
            "ongoing",
            "complete"
          ]
        },
        "evidence_level": {
          "const": "dashboard_notice"
        },
        "evidence": {
          "$ref": "#/definitions/proof"
        },
        "history_status": {
          "enum": [
            "removed",
            "present"
          ]
        },
        "removed_from_google_history_at": {
          "type": "string",
          "format": "date-time",
          "description": "TSEP observation time; not a claimed time of the change made by Google."
        },
        "restored_to_google_history_at": {
          "type": "string",
          "format": "date-time",
          "description": "TSEP observation time; not a claimed time of the change made by Google."
        },
        "history_events": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "status": {
                "enum": [
                  "removed",
                  "restored"
                ]
              },
              "observed_at": {
                "type": "string",
                "format": "date-time"
              },
              "before": {
                "$ref": "#/definitions/proof"
              },
              "after": {
                "$ref": "#/definitions/proof"
              }
            },
            "required": [
              "status",
              "observed_at",
              "before",
              "after"
            ],
            "additionalProperties": true
          }
        }
      },
      "required": [
        "id",
        "title",
        "start",
        "end",
        "start_precision",
        "end_precision",
        "source_start",
        "source_end",
        "duration_minutes",
        "calendar_days",
        "status",
        "evidence_level",
        "evidence"
      ],
      "additionalProperties": true,
      "allOf": [
        {
          "if": {
            "properties": {
              "end": {
                "type": "null"
              }
            }
          },
          "then": {
            "properties": {
              "end_precision": {
                "type": "null"
              },
              "source_end": {
                "type": "null"
              },
              "status": {
                "const": "ongoing"
              },
              "duration_minutes": {
                "type": "null"
              },
              "calendar_days": {
                "type": "null"
              }
            }
          },
          "else": {
            "properties": {
              "end_precision": {
                "enum": [
                  "day",
                  "minute"
                ]
              },
              "source_end": {
                "type": "string"
              },
              "status": {
                "const": "complete"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "start_precision": {
                "const": "day"
              }
            },
            "required": [
              "start_precision"
            ]
          },
          "then": {
            "properties": {
              "start": {
                "type": "string",
                "format": "date"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "start_precision": {
                "const": "minute"
              }
            },
            "required": [
              "start_precision"
            ]
          },
          "then": {
            "properties": {
              "start": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "end_precision": {
                "const": "day"
              }
            },
            "required": [
              "end_precision"
            ]
          },
          "then": {
            "properties": {
              "end": {
                "type": "string",
                "format": "date"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "end_precision": {
                "const": "minute"
              }
            },
            "required": [
              "end_precision"
            ]
          },
          "then": {
            "properties": {
              "end": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "start_precision": {
                "const": "minute"
              },
              "end_precision": {
                "const": "minute"
              }
            },
            "required": [
              "start_precision",
              "end_precision"
            ]
          },
          "then": {
            "properties": {
              "duration_minutes": {
                "type": "integer",
                "minimum": 0
              },
              "calendar_days": {
                "type": "null"
              }
            }
          },
          "else": {
            "properties": {
              "duration_minutes": {
                "type": "null"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "end": {
                "type": "string"
              },
              "duration_minutes": {
                "type": "null"
              }
            },
            "required": [
              "end",
              "duration_minutes"
            ]
          },
          "then": {
            "properties": {
              "calendar_days": {
                "type": "integer",
                "minimum": 0
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "history_status": {
                "const": "removed"
              }
            },
            "required": [
              "history_status"
            ]
          },
          "then": {
            "required": [
              "removed_from_google_history_at",
              "history_events"
            ],
            "properties": {
              "history_events": {
                "minItems": 1
              }
            }
          }
        }
      ]
    }
  }
}
