{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "MafiaSpace game result API v1",
  "description": "Required full terminal result for the existing MafiaSpace rating. Server also validates role counts, unique identities/seats, dates, revision and base points matching the winning team.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "revision",
    "playedAt",
    "finishedAt",
    "gameType",
    "winner",
    "players"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "revision": {
      "type": "integer",
      "minimum": 1,
      "maximum": 2147483647
    },
    "playedAt": {
      "type": "string",
      "format": "date-time"
    },
    "finishedAt": {
      "type": "string",
      "format": "date-time"
    },
    "gameType": {
      "const": "sport_mafia_10"
    },
    "winner": {
      "enum": [
        "civilians",
        "mafia",
        "draw"
      ]
    },
    "externalEventId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "pattern": "^[A-Za-z0-9._-]+$"
    },
    "eventTitle": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "players": {
      "type": "array",
      "minItems": 10,
      "maxItems": 10,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "externalPlayerId",
          "nickname",
          "seat",
          "role",
          "points",
          "isAlive"
        ],
        "properties": {
          "externalPlayerId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[A-Za-z0-9._-]+$"
          },
          "nickname": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "seat": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10
          },
          "role": {
            "enum": [
              "civilian",
              "mafia",
              "don",
              "sheriff"
            ]
          },
          "points": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "base",
              "bonus",
              "penalty"
            ],
            "properties": {
              "base": {
                "type": "string",
                "pattern": "^(?:(?:0|[1-9][0-9]{0,2})(?:\\.[0-9]{1,2})?|1000(?:\\.0{1,2})?)$"
              },
              "bonus": {
                "type": "string",
                "pattern": "^(?:(?:0|[1-9][0-9]{0,2})(?:\\.[0-9]{1,2})?|1000(?:\\.0{1,2})?)$"
              },
              "penalty": {
                "type": "string",
                "pattern": "^(?:(?:0|[1-9][0-9]{0,2})(?:\\.[0-9]{1,2})?|1000(?:\\.0{1,2})?)$"
              }
            }
          },
          "isAlive": {
            "type": "boolean"
          }
        }
      }
    }
  }
}
