{
  "openapi": "3.1.1",
  "info": {
    "title": "Game Event Replay API",
    "version": "1.0.0",
    "summary": "Turn your own goals, points and notes into a running-score replay.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://fielddaygamereplay.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Turn your own goals, points and notes into a running-score replay.",
        "description": "Replay your own match events with named teams, score corrections, lead changes, tied scores and an explicit match duration.\n\nMethodology:\n- Stable chronological ordering preserves input order at equal times. Home/away points accumulate, note events do not change the score, and corrections that produce a negative total are rejected.\n- Lead changes compare successive non-tied leaders; ties count transitions from an unequal to an equal score. These describe the supplied event log, not a verified live feed.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "fieldday_game_replay",
        "x-owner-app": "fieldday",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FielddayGameReplayInput"
              },
              "examples": {
                "example1": {
                  "summary": "Try an example",
                  "value": {}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FielddayGameReplayResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "FielddayGameReplayInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "events": {
            "title": "Game events",
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "minute": {
                  "title": "Minute",
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000
                },
                "second": {
                  "title": "Second",
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000
                },
                "team": {
                  "title": "Team",
                  "type": "string",
                  "enum": [
                    "home",
                    "away",
                    "note"
                  ]
                },
                "points": {
                  "title": "Points (negative for correction)",
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000
                },
                "note": {
                  "title": "Note",
                  "type": "string",
                  "maxLength": 1000
                }
              },
              "required": [
                "minute",
                "second",
                "team",
                "points"
              ]
            },
            "default": [
              {
                "minute": 3,
                "second": 20,
                "team": "home",
                "points": 1,
                "note": "Goal"
              },
              {
                "minute": 8,
                "second": 0,
                "team": "away",
                "points": 1,
                "note": "Equalizer"
              },
              {
                "minute": 12,
                "second": 10,
                "team": "home",
                "points": 1,
                "note": "Goal"
              }
            ]
          },
          "homeName": {
            "title": "Home team",
            "type": "string",
            "maxLength": 60,
            "default": "Home"
          },
          "awayName": {
            "title": "Away team",
            "type": "string",
            "maxLength": 60,
            "default": "Away"
          },
          "durationMinutes": {
            "title": "Match duration (minutes, 0 = last event)",
            "type": "number",
            "minimum": 0,
            "maximum": 360,
            "default": 0
          }
        },
        "required": []
      },
      "FielddayGameReplayResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "home",
              "away",
              "homeName",
              "awayName",
              "durationSeconds",
              "replay",
              "leadChanges",
              "ties",
              "maxHomeLead",
              "maxAwayLead",
              "svg"
            ],
            "properties": {
              "home": {
                "type": "number"
              },
              "away": {
                "type": "number"
              },
              "homeName": {
                "type": "string"
              },
              "awayName": {
                "type": "string"
              },
              "durationSeconds": {
                "type": "number"
              },
              "replay": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "minute",
                    "second",
                    "team",
                    "points",
                    "note",
                    "time",
                    "order",
                    "home",
                    "away",
                    "leader"
                  ],
                  "properties": {
                    "minute": {
                      "type": "number"
                    },
                    "second": {
                      "type": "number"
                    },
                    "team": {
                      "type": "string"
                    },
                    "points": {
                      "type": "number"
                    },
                    "note": {
                      "type": "string"
                    },
                    "time": {
                      "type": "number"
                    },
                    "order": {
                      "type": "number"
                    },
                    "home": {
                      "type": "number"
                    },
                    "away": {
                      "type": "number"
                    },
                    "leader": {
                      "type": "string"
                    }
                  }
                }
              },
              "leadChanges": {
                "type": "number"
              },
              "ties": {
                "type": "number"
              },
              "maxHomeLead": {
                "type": "number"
              },
              "maxAwayLead": {
                "type": "number"
              },
              "svg": {
                "type": "string"
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}