{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://play.unikia.es/schema/achievements.v1.json",
  "title": "Uniplay Hub achievements",
  "description": "achievements.json: the achievements a game can award. The Hub lists them, locked ones included, and the SDK unlocks them by id.",
  "type": "object",
  "required": ["v", "game", "achievements"],
  "properties": {
    "$schema": { "type": "string" },
    "v": { "const": 1, "description": "The file format. Always 1.", "errorMessage": "must be 1" },
    "game": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]*$",
      "description": "The game id, the same as id in unihub.manifest.json.",
      "errorMessage": "must be a game id"
    },
    "achievements": {
      "type": "array",
      "description": "Every achievement, in the order the Hub lists them.",
      "items": {
        "type": "object",
        "required": ["id", "title", "description"],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]*$",
            "description": "Stable id the game unlocks it by. Never change it once published.",
            "errorMessage": "must use a-z, 0-9 and -"
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 40,
            "pattern": "\\S",
            "description": "Short name, at most 40 characters.",
            "errorMessage": "is required, at most 40 characters"
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "pattern": "\\S",
            "description": "How to earn it.",
            "errorMessage": "is required"
          },
          "icon": { "type": "string", "description": "One emoji.", "errorMessage": "must be one emoji" },
          "points": {
            "enum": [5, 10, 25, 50],
            "description": "How much it counts towards the player's total: 5, 10, 25 or 50.",
            "errorMessage": "must be one of 5, 10, 25, 50"
          },
          "hidden": {
            "type": "boolean",
            "description": "Keep its title and description secret until unlocked.",
            "errorMessage": "must be true or false"
          },
          "goal": {
            "type": "number",
            "exclusiveMinimum": 0,
            "description": "For progress achievements: the amount that unlocks it.",
            "errorMessage": "must be a positive number"
          },
          "format": {
            "enum": ["count", "money", "time"],
            "description": "How progress towards goal is shown: count, money or time.",
            "errorMessage": "must be one of count, money, time"
          }
        },
        "dependentRequired": { "format": ["goal"] },
        "errorMessage": { "dependentRequired": "\"format\" only applies with a \"goal\"" }
      }
    }
  }
}
