{
  "openapi": "3.1.0",
  "info": {
    "title": "PadelRank API",
    "version": "1.0.0",
    "summary": "Amateur padel doubles ratings for integrators",
    "description": "Amateur padel doubles ratings for integrators. Current version: /v1. Additive fields may appear on responses. Removing a field or changing the meaning of a status code will use a new major path, with a notice on the developer docs at least 90 days before the old path is removed. JSON only. Timestamps are ISO 8601 UTC. Request bodies are limited to 256 KiB. A handler that runs longer than 25 seconds returns 504. Every partner response includes X-Request-Id. Error JSON always includes error, message, and request_id. Collection endpoints return limit, offset, total, and has_more plus the named array. Live keys need an active or trialing subscription (past-due subscriptions can still read). Test keys are read-only, call this same host and the same data, and can read before a subscription exists. There is no separate sandbox host. Successful calls send monthly quota headers. When per-minute metering is enabled they also send burst headers. 429 includes Retry-After. This document is published at GET /openapi.json without an API key. Human docs: https://developers.padelrank.me/docs — AI agents: https://developers.padelrank.me/llms.txt",
    "contact": {
      "name": "PadelRank developers",
      "url": "https://developers.padelrank.me/contact"
    }
  },
  "servers": [
    {
      "url": "https://api.padelrank.me",
      "description": "Production. Test keys use this same URL."
    }
  ],
  "tags": [
    {
      "name": "System",
      "description": "Unauthenticated health and discovery"
    },
    {
      "name": "Players",
      "description": "Lookup, search, register, form, partners, and integrity"
    },
    {
      "name": "Rankings",
      "description": "Public leaderboard by PadelRank score"
    },
    {
      "name": "Intelligence",
      "description": "Team balance, partnership chemistry, and multi-player session planning"
    },
    {
      "name": "Matches",
      "description": "Submit and read 2v2 results for your partner account"
    },
    {
      "name": "Webhooks",
      "description": "Register HTTPS endpoints for match and rating events"
    },
    {
      "name": "External ratings",
      "description": "Import priors from another scale"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key as a Bearer token. Example: Bearer pr_live_YOUR_API_KEY"
      },
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Same permissions as Bearer. Example: pr_live_YOUR_API_KEY"
      }
    },
    "parameters": {
      "Limit": {
        "name": "limit",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1
        }
      },
      "Offset": {
        "name": "offset",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "schemas": {
      "Rating": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "padelrank_score",
          "confidence_level",
          "confidence_label",
          "matches_played"
        ],
        "properties": {
          "padelrank_score": {
            "type": "integer",
            "minimum": 0,
            "description": "Public skill score generated by the proprietary ranking engine. Floored at 0. Not capped.",
            "example": 2840
          },
          "confidence_level": {
            "type": "string",
            "enum": [
              "provisional",
              "established",
              "verified"
            ],
            "description": "Machine-readable confidence band based on completed matches and rating stability."
          },
          "confidence_label": {
            "type": "string",
            "description": "Human-readable confidence label for UI display.",
            "example": "Medium confidence"
          },
          "matches_played": {
            "type": "integer",
            "minimum": 0,
            "description": "Count of completed matches that contributed to the rating."
          }
        }
      },
      "Player": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "username",
          "display_name",
          "country_code",
          "city",
          "rating",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "username": {
            "type": "string",
            "pattern": "^[a-z0-9_]{3,30}$",
            "example": "maria_s"
          },
          "display_name": {
            "type": [
              "string",
              "null"
            ],
            "example": "Maria Silva"
          },
          "country_code": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 2,
            "maxLength": 2,
            "example": "PT"
          },
          "city": {
            "type": [
              "string",
              "null"
            ],
            "example": "Lisbon"
          },
          "rating": {
            "$ref": "#/components/schemas/Rating"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PlayerSearchHit": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "username",
          "display_name",
          "country_code",
          "city"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "username": {
            "type": "string"
          },
          "display_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "country_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "RankingRow": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "rank",
          "id",
          "username",
          "display_name",
          "country_code",
          "city",
          "rating"
        ],
        "properties": {
          "rank": {
            "type": "integer",
            "description": "Position inside this filtered page, starting at offset + 1."
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "username": {
            "type": "string"
          },
          "display_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "country_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "rating": {
            "$ref": "#/components/schemas/Rating"
          }
        }
      },
      "CreatePlayerRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "username"
        ],
        "properties": {
          "username": {
            "type": "string",
            "pattern": "^[a-z0-9_]{3,30}$",
            "description": "Lowercased public handle. 3–30 characters: a-z, 0-9, underscore.",
            "example": "maria_s"
          },
          "display_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "example": "Maria Silva"
          },
          "country_code": {
            "type": "string",
            "pattern": "^[A-Z]{2}$",
            "description": "ISO 3166-1 alpha-2, uppercased.",
            "example": "PT"
          },
          "city": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "example": "Lisbon"
          },
          "profile_is_public": {
            "type": "boolean",
            "default": true,
            "description": "Private profiles are not returned by GET player, search, rankings, or predict."
          }
        }
      },
      "CreatePlayerResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "username",
          "created"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "username": {
            "type": "string"
          },
          "created": {
            "type": "boolean",
            "description": "true when a new row was inserted; false when the username already existed."
          }
        }
      },
      "PredictRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "player_ids",
          "format"
        ],
        "properties": {
          "format": {
            "type": "string",
            "enum": [
              "2v2"
            ]
          },
          "player_ids": {
            "type": "array",
            "minItems": 4,
            "maxItems": 4,
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Four distinct public player ids in court order: team A left, team A right, team B left, team B right."
          }
        },
        "example": {
          "format": "2v2",
          "player_ids": [
            "11111111-1111-4111-8111-111111111111",
            "22222222-2222-4222-8222-222222222222",
            "33333333-3333-4333-8333-333333333333",
            "44444444-4444-4444-8444-444444444444"
          ]
        }
      },
      "PredictResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "draw_probability",
          "balance_rating",
          "team_a",
          "team_b"
        ],
        "properties": {
          "draw_probability": {
            "type": "number",
            "description": "Relative pairing score for this foursome. Higher means more even among pairings you compare. Not a promise the match will be tied.",
            "example": 0.11
          },
          "balance_rating": {
            "type": "string",
            "enum": [
              "high",
              "medium",
              "low"
            ],
            "description": "high when draw_probability >= 0.12, medium when >= 0.07, otherwise low."
          },
          "team_a": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "team_b": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          }
        }
      },
      "MatchParticipantInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "team",
          "court_position"
        ],
        "properties": {
          "profile_id": {
            "type": "string",
            "format": "uuid"
          },
          "username": {
            "type": "string",
            "pattern": "^[a-z0-9_]{3,30}$"
          },
          "team": {
            "type": "string",
            "enum": [
              "A",
              "B"
            ]
          },
          "court_position": {
            "type": "string",
            "enum": [
              "left",
              "right"
            ]
          }
        },
        "description": "Provide profile_id or username (at least one)."
      },
      "SetScore": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "set_number",
          "team_a_games",
          "team_b_games"
        ],
        "properties": {
          "set_number": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5
          },
          "team_a_games": {
            "type": "integer",
            "minimum": 0,
            "maximum": 20
          },
          "team_b_games": {
            "type": "integer",
            "minimum": 0,
            "maximum": 20
          },
          "is_tiebreak": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "CreateMatchRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "played_at",
          "winning_team",
          "participants"
        ],
        "properties": {
          "external_ref": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Partner-owned idempotency reference for this result.",
            "example": "your-app-match-9821"
          },
          "played_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the match was played (ISO 8601).",
            "example": "2026-06-16T18:30:00Z"
          },
          "winning_team": {
            "type": "string",
            "enum": [
              "A",
              "B"
            ]
          },
          "trust_tier": {
            "type": "string",
            "enum": [
              "partner_attested",
              "player_confirmed",
              "tournament_official",
              "imported"
            ],
            "default": "partner_attested",
            "description": "Authority of the result. partner_attested, tournament_official, and imported complete and may update ratings. player_confirmed stays pending and does not update ratings in this version. Official results move ratings further than attested or imported ones."
          },
          "set_scores": {
            "type": "array",
            "maxItems": 5,
            "items": {
              "$ref": "#/components/schemas/SetScore"
            },
            "description": "Optional. Must agree with winning_team. Drawn sets are rejected."
          },
          "participants": {
            "type": "array",
            "minItems": 4,
            "maxItems": 4,
            "items": {
              "$ref": "#/components/schemas/MatchParticipantInput"
            },
            "description": "Exactly four players: each team needs left and right."
          }
        }
      },
      "CreateMatchResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "status",
          "rating_applied"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "completed",
              "disputed",
              "cancelled"
            ]
          },
          "rating_applied": {
            "type": "boolean",
            "description": "true only when a rating update was saved for this request."
          },
          "idempotent_replay": {
            "type": "boolean",
            "description": "Present and true when the same ref returned an existing match."
          }
        }
      },
      "PartnerMatch": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "played_at",
          "winning_team",
          "status",
          "trust_tier",
          "external_ref",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "played_at": {
            "type": "string",
            "format": "date-time"
          },
          "winning_team": {
            "type": "string",
            "enum": [
              "A",
              "B"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "completed",
              "disputed",
              "cancelled"
            ]
          },
          "trust_tier": {
            "type": "string",
            "enum": [
              "partner_attested",
              "player_confirmed",
              "tournament_official",
              "imported"
            ]
          },
          "external_ref": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "MatchParticipantView": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "profile_id",
          "username",
          "team",
          "court_position",
          "won"
        ],
        "properties": {
          "profile_id": {
            "type": "string",
            "format": "uuid"
          },
          "username": {
            "type": [
              "string",
              "null"
            ]
          },
          "team": {
            "type": "string",
            "enum": [
              "A",
              "B"
            ]
          },
          "court_position": {
            "type": "string",
            "enum": [
              "left",
              "right"
            ]
          },
          "won": {
            "type": "boolean"
          }
        }
      },
      "ScorelineSummary": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "total_sets",
          "total_games",
          "close_sets",
          "blowout_sets",
          "straight_sets",
          "tie_break_sets",
          "max_set_game_gap",
          "closeness"
        ],
        "properties": {
          "total_sets": {
            "type": "integer"
          },
          "total_games": {
            "type": "integer"
          },
          "close_sets": {
            "type": "integer"
          },
          "blowout_sets": {
            "type": "integer"
          },
          "straight_sets": {
            "type": "boolean"
          },
          "tie_break_sets": {
            "type": "integer"
          },
          "max_set_game_gap": {
            "type": "integer"
          },
          "closeness": {
            "type": "string",
            "enum": [
              "tight",
              "normal",
              "one_sided"
            ]
          }
        }
      },
      "MatchDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/PartnerMatch"
          },
          {
            "type": "object",
            "required": [
              "participants"
            ],
            "properties": {
              "participants": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/MatchParticipantView"
                }
              },
              "set_scores": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/SetScore"
                }
              },
              "scoreline": {
                "anyOf": [
                  {
                    "$ref": "#/components/schemas/ScorelineSummary"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          }
        ]
      },
      "FormCard": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "window",
          "matches_in_window",
          "wins",
          "losses",
          "win_rate",
          "close_match_rate",
          "official_match_share",
          "rating_delta",
          "form_index",
          "form_label"
        ],
        "properties": {
          "window": {
            "type": "integer"
          },
          "matches_in_window": {
            "type": "integer"
          },
          "wins": {
            "type": "integer"
          },
          "losses": {
            "type": "integer"
          },
          "win_rate": {
            "type": "number"
          },
          "close_match_rate": {
            "type": [
              "number",
              "null"
            ]
          },
          "official_match_share": {
            "type": "number"
          },
          "rating_delta": {
            "type": "integer"
          },
          "form_index": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "description": "Opaque 0–100 form score for partner UIs. Not an internal rating parameter."
          },
          "form_label": {
            "type": "string",
            "enum": [
              "hot",
              "steady",
              "cold",
              "unknown"
            ]
          }
        }
      },
      "ChemistryCard": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sample_matches",
          "wins",
          "losses",
          "win_rate",
          "synergy_score",
          "confidence_level",
          "preferred_side_a",
          "preferred_side_b"
        ],
        "properties": {
          "sample_matches": {
            "type": "integer"
          },
          "wins": {
            "type": "integer"
          },
          "losses": {
            "type": "integer"
          },
          "win_rate": {
            "type": "number"
          },
          "synergy_score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "description": "Opaque partnership score for partner UIs."
          },
          "confidence_level": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high"
            ]
          },
          "preferred_side_a": {
            "type": "string",
            "enum": [
              "left",
              "right",
              "either"
            ]
          },
          "preferred_side_b": {
            "type": "string",
            "enum": [
              "left",
              "right",
              "either"
            ]
          }
        }
      },
      "SessionRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "player_ids"
        ],
        "properties": {
          "format": {
            "type": "string",
            "enum": [
              "americano",
              "fixed_teams"
            ],
            "default": "americano"
          },
          "rounds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20,
            "default": 3
          },
          "player_ids": {
            "type": "array",
            "minItems": 4,
            "maxItems": 32,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          }
        }
      },
      "SessionMatchPlan": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "team_a",
          "team_b",
          "draw_probability",
          "balance_rating"
        ],
        "properties": {
          "team_a": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "team_b": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "draw_probability": {
            "type": "number"
          },
          "balance_rating": {
            "type": "string",
            "enum": [
              "high",
              "medium",
              "low"
            ]
          }
        }
      },
      "CreateWebhookRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "HTTPS callback URL.",
            "example": "https://example.com/hooks/padelrank"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "match.completed",
                "rating.updated"
              ]
            },
            "default": [
              "match.completed",
              "rating.updated"
            ]
          }
        }
      },
      "WebhookEndpoint": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "url",
          "events",
          "is_active",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "match.completed",
                "rating.updated"
              ]
            }
          },
          "is_active": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_success_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "failure_count": {
            "type": "integer"
          },
          "signing_secret": {
            "type": "string",
            "description": "Returned only on create. Store it; it is not shown again."
          }
        }
      },
      "ExternalRatingEntry": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "profile_id"
        ],
        "properties": {
          "profile_id": {
            "type": "string",
            "format": "uuid"
          },
          "external_player_ref": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          },
          "raw_rating": {
            "type": [
              "number",
              "null"
            ]
          },
          "raw_label": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 120
          },
          "normalized_score": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 5000,
            "description": "Optional prior on the public PadelRank score scale. Does not change the live score."
          },
          "rating_observed_at": {
            "type": "string",
            "format": "date-time"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true,
            "description": "Partner-defined key/value metadata for the import row."
          }
        }
      },
      "ExternalRatingsUpsertRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "provider_id",
          "entries"
        ],
        "properties": {
          "provider_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "description": "Configured provider identifier for the calling partner."
          },
          "dry_run": {
            "type": "boolean",
            "description": "When true, validate without writing."
          },
          "entries": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "$ref": "#/components/schemas/ExternalRatingEntry"
            }
          }
        }
      },
      "ExternalRatingsUpsertResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "ok",
          "provider_id",
          "total"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "dry_run": {
            "type": "boolean"
          },
          "provider_id": {
            "type": "string"
          },
          "total": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Stable machine-readable error code.",
            "example": "validation_error"
          },
          "message": {
            "type": "string",
            "description": "Human-readable explanation."
          },
          "request_id": {
            "type": "string",
            "description": "Correlates with the X-Request-Id response header."
          },
          "reason": {
            "type": "string"
          },
          "required_scopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "quota": {
            "type": "integer"
          },
          "used": {
            "type": "integer"
          },
          "match_id": {
            "type": "string",
            "format": "uuid"
          },
          "player_id": {
            "type": "string",
            "format": "uuid"
          },
          "unknown_count": {
            "type": "integer"
          }
        }
      },
      "Page": {
        "type": "object",
        "required": [
          "limit",
          "offset",
          "total",
          "has_more"
        ],
        "properties": {
          "limit": {
            "type": "integer"
          },
          "offset": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          },
          "has_more": {
            "type": "boolean"
          }
        }
      },
      "VersionIndex": {
        "type": "object",
        "required": [
          "version",
          "docs",
          "endpoints"
        ],
        "properties": {
          "version": {
            "type": "string",
            "example": "1"
          },
          "docs": {
            "type": "string",
            "format": "uri"
          },
          "endpoints": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Map of logical names to path templates."
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or unknown API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Missing scope, or a test key used for a write",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PaymentRequired": {
        "description": "Live key without a usable subscription",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Unknown, private, or another partner's resource",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ValidationError": {
        "description": "Body, query, or path failed validation",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Monthly quota or per-minute burst exceeded. Check Retry-After.",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            },
            "description": "Seconds to wait before retrying."
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "bearer": []
    },
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "System"
        ],
        "security": [],
        "summary": "Liveness",
        "description": "Process is up. No authentication.",
        "responses": {
          "200": {
            "description": "Process is up",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "service",
                    "timestamp"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ok"
                      ]
                    },
                    "service": {
                      "type": "string",
                      "enum": [
                        "api"
                      ]
                    },
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ready": {
      "get": {
        "tags": [
          "System"
        ],
        "security": [],
        "summary": "Readiness",
        "description": "Database is reachable. Body uses status and reason, not the partner error envelope.",
        "responses": {
          "200": {
            "description": "Database is reachable",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "service",
                    "timestamp"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ready"
                      ]
                    },
                    "service": {
                      "type": "string",
                      "enum": [
                        "api"
                      ]
                    },
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Not ready. Body uses status and reason, not the partner error envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "reason"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "not_ready"
                      ]
                    },
                    "reason": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1": {
      "get": {
        "tags": [
          "System"
        ],
        "summary": "Version and endpoint index",
        "description": "Requires a valid API key. No specific scope.",
        "responses": {
          "200": {
            "description": "version, docs URL, and endpoint map",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VersionIndex"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/players/{username}": {
      "get": {
        "tags": [
          "Players"
        ],
        "summary": "Get a public player",
        "description": "Returns public profile fields and the partner-safe rating object. Unknown or private usernames return 404 with the same shape.",
        "x-required-scopes": [
          "read:players"
        ],
        "parameters": [
          {
            "name": "username",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9_]{3,30}$"
            },
            "description": "Public username (trimmed and lowercased by the API)."
          }
        ],
        "responses": {
          "200": {
            "description": "Player, rating, and created_at",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Player"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/players/search": {
      "get": {
        "tags": [
          "Players"
        ],
        "summary": "Prefix search of public usernames",
        "description": "Ordered by username. q is a literal prefix. % and _ are not wildcards.",
        "x-required-scopes": [
          "read:players"
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 64
            },
            "description": "Literal username prefix (at least 2 characters)."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "results plus limit, offset, total, has_more",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "results",
                    "limit",
                    "offset",
                    "total",
                    "has_more"
                  ],
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PlayerSearchHit"
                      }
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/players": {
      "post": {
        "tags": [
          "Players"
        ],
        "summary": "Register a player",
        "description": "Same username returns 200 with created false, including a concurrent duplicate. There is no delete endpoint. Requires a live key with write:players.",
        "x-required-scopes": [
          "write:players"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePlayerRequest"
              },
              "example": {
                "username": "maria_s",
                "display_name": "Maria Silva",
                "country_code": "PT"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Username already existed. created false",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatePlayerResponse"
                }
              }
            }
          },
          "201": {
            "description": "Created. Body includes id, username, created true",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatePlayerResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/rankings": {
      "get": {
        "tags": [
          "Rankings"
        ],
        "summary": "Public leaderboard",
        "description": "Ordered by PadelRank score, highest first. rank is the position inside this filtered page, starting at offset + 1. country_code is an exact code. city is a case-insensitive exact match, not a substring.",
        "x-required-scopes": [
          "read:rankings"
        ],
        "parameters": [
          {
            "name": "country_code",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 2,
              "pattern": "^[A-Z]{2}$"
            }
          },
          {
            "name": "city",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "rankings plus limit, offset, total, has_more",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "rankings",
                    "limit",
                    "offset",
                    "total",
                    "has_more"
                  ],
                  "properties": {
                    "rankings": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/RankingRow"
                      }
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/players/{username}/form": {
      "get": {
        "tags": [
          "Players"
        ],
        "summary": "Rolling form for a public player",
        "description": "Recent completed-match form card for engagement and fantasy eligibility. form_index is an opaque 0–100 product score.",
        "x-required-scopes": [
          "read:players"
        ],
        "parameters": [
          {
            "name": "username",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9_]{3,30}$"
            }
          },
          {
            "name": "window",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Form card",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "username",
                    "form"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "username": {
                      "type": "string"
                    },
                    "form": {
                      "$ref": "#/components/schemas/FormCard"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/players/{username}/partners": {
      "get": {
        "tags": [
          "Players"
        ],
        "summary": "Top partnership affinities",
        "description": "Players this athlete has partnered with most successfully in completed matches.",
        "x-required-scopes": [
          "read:intelligence"
        ],
        "parameters": [
          {
            "name": "username",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9_]{3,30}$"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked partners",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "username",
                    "partners"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "username": {
                      "type": "string"
                    },
                    "partners": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/players/{username}/integrity": {
      "get": {
        "tags": [
          "Players"
        ],
        "summary": "Integrity risk band",
        "description": "Opaque risk band and signal labels for league hosts. Heuristic product signal — not proof of misconduct.",
        "x-required-scopes": [
          "read:intelligence"
        ],
        "parameters": [
          {
            "name": "username",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9_]{3,30}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Integrity card",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "username",
                    "integrity"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "username": {
                      "type": "string"
                    },
                    "integrity": {
                      "type": "object",
                      "required": [
                        "risk_band",
                        "signals",
                        "matches_reviewed"
                      ],
                      "properties": {
                        "risk_band": {
                          "type": "string",
                          "enum": [
                            "low",
                            "medium",
                            "high"
                          ]
                        },
                        "signals": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "matches_reviewed": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/intelligence/predict": {
      "post": {
        "tags": [
          "Intelligence"
        ],
        "summary": "Team balance for four distinct public players",
        "description": "player_ids order is team A left, team A right, team B left, team B right. draw_probability is a relative pairing score, not a promise the match will be tied. balance_rating is high at 0.12 or above, medium at 0.07 or above, otherwise low. Allowed for test keys. Metered as a predict call.",
        "x-required-scopes": [
          "read:intelligence"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PredictRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "draw_probability, balance_rating, team_a, team_b",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PredictResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "description": "Invalid roster or a player is missing or private",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/intelligence/chemistry": {
      "get": {
        "tags": [
          "Intelligence"
        ],
        "summary": "Partnership chemistry for two public players",
        "description": "How two players perform when they share a team. synergy_score is opaque 0–100. Metered as a predict call.",
        "x-required-scopes": [
          "read:intelligence"
        ],
        "parameters": [
          {
            "name": "player_a",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "player_b",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Chemistry card",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "type": "object",
                      "required": [
                        "player_a",
                        "player_b"
                      ],
                      "properties": {
                        "player_a": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "player_b": {
                          "type": "string",
                          "format": "uuid"
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/ChemistryCard"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/intelligence/session": {
      "post": {
        "tags": [
          "Intelligence"
        ],
        "summary": "Plan balanced rounds for N public players",
        "description": "Americano-style or fixed-order session planner. Maximises relative balance per foursome and rotates sit-outs when needed. Metered as a predict call.",
        "x-required-scopes": [
          "read:intelligence"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SessionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Round plan",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "format",
                    "rounds"
                  ],
                  "properties": {
                    "format": {
                      "type": "string",
                      "enum": [
                        "americano",
                        "fixed_teams"
                      ]
                    },
                    "rounds": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "round",
                          "matches",
                          "sitting_out"
                        ],
                        "properties": {
                          "round": {
                            "type": "integer"
                          },
                          "matches": {
                            "type": "array",
                            "items": {
                              "$ref": "#/components/schemas/SessionMatchPlan"
                            }
                          },
                          "sitting_out": {
                            "type": "array",
                            "items": {
                              "type": "string",
                              "format": "uuid"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/matches": {
      "get": {
        "tags": [
          "Matches"
        ],
        "summary": "List matches submitted by the calling partner",
        "description": "Scope: write:matches or read:players. Newest first. Optional filters: external_ref (exact) and status (pending, completed, disputed, cancelled). Does not include other partners' matches.",
        "x-required-scopes": [
          "write:matches",
          "read:players"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000,
              "default": 0
            }
          },
          {
            "name": "external_ref",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "completed",
                "disputed",
                "cancelled"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "matches plus limit, offset, total, has_more",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "matches",
                    "limit",
                    "offset",
                    "total",
                    "has_more"
                  ],
                  "properties": {
                    "matches": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PartnerMatch"
                      }
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "tags": [
          "Matches"
        ],
        "summary": "Submit a 2v2 result",
        "description": "trust_tier selects authority. partner_attested, tournament_official, and imported are completed and update ratings before the response. An official result moves ratings further than an attested or imported result. player_confirmed stays pending and does not update ratings. The winner and the trust tier determine the update. Set scores, when sent, must agree with the winner. A drawn set is rejected. Court side is required and stored. Retries with the same external_ref or Idempotency-Key and the same winner and trust tier return 200 idempotent_replay and do not apply the result again. A different winner or trust tier for that ref returns 409. There is no delete endpoint.",
        "x-required-scopes": [
          "write:matches"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9._:-]{8,128}$"
            },
            "description": "Optional. Letters, digits, and . _ : - only. Combined with external_ref for safe retries."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateMatchRequest"
              },
              "example": {
                "external_ref": "your-app-match-9821",
                "played_at": "2026-06-16T18:30:00Z",
                "winning_team": "A",
                "trust_tier": "partner_attested",
                "participants": [
                  {
                    "username": "maria_s",
                    "team": "A",
                    "court_position": "left"
                  },
                  {
                    "username": "joao_p",
                    "team": "A",
                    "court_position": "right"
                  },
                  {
                    "username": "ana_r",
                    "team": "B",
                    "court_position": "left"
                  },
                  {
                    "username": "pedro_l",
                    "team": "B",
                    "court_position": "right"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Idempotent replay",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateMatchResponse"
                }
              }
            }
          },
          "201": {
            "description": "Created. rating_applied is true when a rating write committed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateMatchResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "description": "Same ref, different result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid body or unknown participant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "description": "Stored as disputed when the rating write fails",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/matches/{id}": {
      "get": {
        "tags": [
          "Matches"
        ],
        "summary": "Read a match submitted by the calling partner",
        "description": "Scope: write:matches or read:players. Includes set_scores and a partner-safe scoreline summary when sets were stored. Another partner's match is returned as not found.",
        "x-required-scopes": [
          "write:matches",
          "read:players"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Match, participants, optional set scores and scoreline",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MatchDetail"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/matches/{id}/rating-story": {
      "get": {
        "tags": [
          "Matches"
        ],
        "summary": "Partner-safe post-match rating narrative",
        "description": "Human-readable reasons for score movement after a completed rated match. Scope: write:matches or read:players.",
        "x-required-scopes": [
          "write:matches",
          "read:players"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Narrative per participant, or available false when no rating events exist",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "match_id",
                    "available",
                    "participants"
                  ],
                  "properties": {
                    "match_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "available": {
                      "type": "boolean"
                    },
                    "participants": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/webhooks": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "summary": "List webhook endpoints",
        "x-required-scopes": [
          "write:webhooks"
        ],
        "responses": {
          "200": {
            "description": "Active endpoints for the partner",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "endpoints"
                  ],
                  "properties": {
                    "endpoints": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookEndpoint"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Register a webhook endpoint",
        "description": "HTTPS only. signing_secret is returned once. Deliveries send X-PadelRank-Timestamp and X-PadelRank-Signature (HMAC-SHA256 of timestamp.body).",
        "x-required-scopes": [
          "write:webhooks"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created; includes signing_secret",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/webhooks/{id}": {
      "delete": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Revoke a webhook endpoint",
        "x-required-scopes": [
          "write:webhooks"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "revoked"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "revoked": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/external-ratings/upsert": {
      "post": {
        "tags": [
          "External ratings"
        ],
        "summary": "Import external priors",
        "description": "Stores a provider value for players that already exist. Optional normalized_score uses the public score scale. This does not change the PadelRank score. dry_run validates without writing. Upsert key is player plus provider. At most 500 entries per request.",
        "x-required-scopes": [
          "write:external-ratings"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExternalRatingsUpsertRequest"
              },
              "example": {
                "provider_id": "your_provider",
                "dry_run": false,
                "entries": [
                  {
                    "profile_id": "11111111-1111-4111-8111-111111111111",
                    "external_player_ref": "ext-maria",
                    "normalized_score": 2800
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Upserted, or dry_run true",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExternalRatingsUpsertResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "Unknown provider",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Provider inactive",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid body or unknown players",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    }
  }
}
