{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/livetennisapi-com/json-schema/livetennisapi-com-head-to-head-schema.json",
  "title": "HeadToHead",
  "description": "The record between two players across both halves of the product — the results archive (1968–2022) and our own completed matches (2023→now). Totals count meetings with a KNOWN winner; `undecided` counts the rest.",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/livetennisapi-com-h2h-api-openapi.yml#/components/schemas/HeadToHead",
  "type": "object",
  "properties": {
    "players": {
      "type": [
        "object",
        "null"
      ],
      "description": "The resolved names ({\"p1\":{\"name\"}, \"p2\":{\"name\"}}); null when no player matches the fragments."
    },
    "totals": {
      "type": "object",
      "properties": {
        "p1_wins": {
          "type": "integer"
        },
        "p2_wins": {
          "type": "integer"
        },
        "meetings": {
          "type": "integer"
        },
        "undecided": {
          "type": "integer",
          "description": "Meetings with no derivable winner (never counted in wins)."
        }
      }
    },
    "by_surface": {
      "type": "object",
      "description": "Per-surface win split of the decided meetings; keys are surface names plus 'unknown'.",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "p1": {
            "type": "integer"
          },
          "p2": {
            "type": "integer"
          }
        }
      }
    },
    "meetings": {
      "type": "array",
      "description": "Newest first, capped at 200. `era` says which half served the row — 'archive' rows carry `archive_match_id`/`level`/`score`; 'current' rows carry `match_id`/`round_code` and read their score from the match endpoints. `winner` is 1|2 OF THIS H2H (p1/p2 as requested), null when underivable.",
      "items": {
        "type": "object",
        "properties": {
          "era": {
            "type": "string",
            "enum": [
              "archive",
              "current"
            ]
          },
          "date": {
            "type": [
              "string",
              "null"
            ]
          },
          "tournament": {
            "type": [
              "string",
              "null"
            ]
          },
          "level": {
            "type": [
              "string",
              "null"
            ]
          },
          "round": {
            "type": [
              "string",
              "null"
            ]
          },
          "surface": {
            "type": [
              "string",
              "null"
            ]
          },
          "score": {
            "type": [
              "string",
              "null"
            ]
          },
          "outcome": {
            "type": [
              "string",
              "null"
            ]
          },
          "winner": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      }
    },
    "stats": {
      "type": [
        "object",
        "null"
      ],
      "description": "ULTRA only — per-player serve/return/break-point aggregates over the pairing, keyed `p1`/`p2`. Each side carries `archive_serve` (serve-side figures, meetings from 1991) and `current` (2023+, adding return and break-point conversion, aces and winners), each with its own `meetings_with_stats` sample size. Absent below ULTRA."
    }
  }
}