{
  "openapi": "3.1.0",
  "info": {
    "title": "Crown Data API",
    "version": "1.0.0",
    "description": "足球和篮球的赛事、赔率与完场赛果。赔率字段按皇冠上游原样保留。"
  },
  "security": [
    {
      "siteKey": []
    }
  ],
  "tags": [
    {
      "name": "赛事"
    }
  ],
  "paths": {
    "/v1/events": {
      "get": {
        "tags": [
          "赛事"
        ],
        "operationId": "listEvents",
        "summary": "读取赛事列表",
        "parameters": [
          {
            "name": "sport",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "ft",
                "bk"
              ],
              "default": "ft"
            }
          },
          {
            "name": "phase",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "live",
                "today",
                "early"
              ],
              "default": "live"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "赛事快照",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Snapshot"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Event"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "站点 Key 无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "采集快照尚未生成",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/events/{id}/odds": {
      "get": {
        "tags": [
          "赛事"
        ],
        "operationId": "getOdds",
        "summary": "读取单场盘口赔率",
        "parameters": [
          {
            "$ref": "#/components/parameters/EventId"
          }
        ],
        "responses": {
          "200": {
            "description": "赔率快照，可用盘口取决于上游",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Snapshot"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "additionalProperties": true
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "站点 Key 无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "采集快照尚未生成",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/events/{id}/result": {
      "get": {
        "tags": [
          "赛事"
        ],
        "operationId": "getResult",
        "summary": "读取单场完场赛果",
        "parameters": [
          {
            "$ref": "#/components/parameters/EventId"
          }
        ],
        "responses": {
          "200": {
            "description": "赛果快照",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Snapshot"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Result"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "站点 Key 无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "赛果尚未采集或关联",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "采集快照尚未生成",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "siteKey": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "parameters": {
      "EventId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^(ft|bk)-[0-9]{1,24}$"
        },
        "example": "ft-12345"
      }
    },
    "schemas": {
      "Snapshot": {
        "type": "object",
        "required": [
          "data",
          "source",
          "updated_at",
          "stale"
        ],
        "properties": {
          "data": {},
          "source": {
            "const": "Crown"
          },
          "event_id": {
            "type": "string"
          },
          "updated_at": {
            "type": "integer",
            "description": "最后一次成功采集的 Unix 秒"
          },
          "stale": {
            "type": "boolean",
            "description": "数据超过时效、最近一次采集失败或对应上游暂停"
          }
        }
      },
      "Event": {
        "type": "object",
        "required": [
          "id",
          "sport",
          "phase",
          "home",
          "away"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "sport": {
            "enum": [
              "ft",
              "bk"
            ]
          },
          "phase": {
            "enum": [
              "live",
              "today",
              "early"
            ]
          },
          "home": {
            "type": "string"
          },
          "away": {
            "type": "string"
          },
          "league": {
            "type": [
              "string",
              "null"
            ]
          },
          "league_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "kickoff": {
            "type": [
              "string",
              "null"
            ],
            "description": "上游时间字符串"
          },
          "status": {
            "type": ["string", "null"],
            "description": "上游赛事状态值"
          },
          "score": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Score"
              },
              {
                "type": "null"
              }
            ]
          },
          "provider_event_id": {
            "type": "string"
          },
          "gid": {
            "type": [
              "string",
              "null"
            ]
          },
          "gidm": {
            "type": [
              "string",
              "null"
            ]
          },
          "ecid": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Score": {
        "type": "object",
        "required": [
          "home",
          "away"
        ],
        "properties": {
          "home": {
            "type": "integer"
          },
          "away": {
            "type": "integer"
          }
        }
      },
      "Result": {
        "type": "object",
        "required": [
          "gid",
          "sport",
          "status",
          "score",
          "segments",
          "date"
        ],
        "properties": {
          "gid": {
            "type": "string"
          },
          "sport": {
            "enum": [
              "ft",
              "bk"
            ]
          },
          "date": {
            "type": "string",
            "format": "date"
          },
          "status": {
            "type": [
              "string",
              "null"
            ],
            "description": "上游状态值"
          },
          "score": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Score"
              },
              {
                "type": "null"
              }
            ]
          },
          "segments": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/Score"
            },
            "description": "常见分段为 full_time、first_half、second_half、q1–q4、overtime，按上游数据可用性返回"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  }
}
