{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://wristdope.com/skills/match/schema.json",
  "title": "Wrist Dope match file (.wdmatch), schema version 1",
  "description": "One match as stages, targets (label + range in yards) and a shoot order. Read by Wrist Dope on iOS, Apple Watch, Android and Wear OS. Holds are never stored; the app solves them live.",
  "type": "object",
  "required": ["format", "matches"],
  "additionalProperties": false,
  "properties": {
    "format": { "const": "wristdope.match-backup" },
    "schemaVersion": { "enum": [1, null], "description": "Omit or 1. A higher number is refused as 'from a newer version'." },
    "exportedAt": { "anyOf": [{ "$ref": "#/$defs/utcDate" }, { "type": "null" }] },
    "appVersion": { "type": ["string", "null"] },
    "platform": { "type": ["string", "null"], "description": "Who wrote the file, for example 'assistant'." },
    "matches": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1,
      "items": { "$ref": "#/$defs/match" }
    }
  },
  "$defs": {
    "uuid": {
      "type": "string",
      "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$",
      "description": "A fresh UUID v4, uppercase. Unique within the file (a step's targetID repeats a target's id on purpose)."
    },
    "utcDate": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$",
      "description": "UTC, whole seconds, trailing Z: 2026-10-17T14:00:00Z. No fractional seconds, no offset."
    },
    "match": {
      "type": "object",
      "required": ["id", "name", "createdAt", "lastModified", "stages"],
      "additionalProperties": false,
      "properties": {
        "id": { "$ref": "#/$defs/uuid" },
        "name": { "type": "string", "minLength": 1, "pattern": "\\S", "description": "Shown in the app's match list. Use the match's own name." },
        "createdAt": { "$ref": "#/$defs/utcDate" },
        "lastModified": { "$ref": "#/$defs/utcDate" },
        "stages": { "type": "array", "items": { "$ref": "#/$defs/stage" } }
      }
    },
    "stage": {
      "type": "object",
      "required": ["id", "name", "targets", "sequence"],
      "additionalProperties": false,
      "properties": {
        "id": { "$ref": "#/$defs/uuid" },
        "name": { "type": "string", "minLength": 1, "pattern": "\\S", "description": "'Stage 3' or the sheet's stage name." },
        "parSeconds": { "type": ["integer", "null"], "minimum": 0, "description": "Par time in seconds. Omit when the sheet has none." },
        "roundLimit": { "type": ["integer", "null"], "minimum": 0, "description": "Round count for the stage. Omit when the sheet has none." },
        "briefNote": { "type": ["string", "null"], "description": "One short line from the stage brief." },
        "targets": { "type": "array", "items": { "$ref": "#/$defs/target" } },
        "sequence": {
          "type": "array",
          "items": { "$ref": "#/$defs/step" },
          "description": "The shoot order. A target may appear more than once."
        },
        "hunterBlind": { "type": ["boolean", "null"], "description": "NRL Hunter blind stage: targets are found on the clock; targets and sequence stay empty." },
        "positionNames": {
          "type": ["object", "null"],
          "propertyNames": { "type": "string", "pattern": "^[1-9][0-9]*$" },
          "additionalProperties": { "type": "string", "pattern": "^\\s*\\S([\\s\\S]{0,6}\\S)?\\s*$" },
          "description": "Names the sheet itself gives its positions ('Tripod', 'Roof'), keyed by the position number as a string ('1', '2'). 1 to 8 characters each; the card prints the name in place of 'P1'. Omit when the sheet names none; never invent a name."
        },
        "positionNotes": {
          "type": ["object", "null"],
          "propertyNames": { "type": "string", "pattern": "^[1-9][0-9]*$" },
          "additionalProperties": { "type": "string", "pattern": "\\S" },
          "description": "Each position's description from the sheet ('Left side, right leg on rooftop'), keyed by the position number as a string ('1', '2'). Written once here, never repeated on the steps."
        }
      }
    },
    "target": {
      "type": "object",
      "required": ["id", "label", "range"],
      "additionalProperties": false,
      "properties": {
        "id": { "$ref": "#/$defs/uuid" },
        "label": { "type": "string", "minLength": 1, "maxLength": 8, "pattern": "^\\S(.*\\S)?$", "description": "'T1', 'T2' in sheet order, or a short name ('KYL1', 'LG', 'Ram')." },
        "range": { "type": "number", "exclusiveMinimum": 0, "description": "Yards. Convert metres: yards = metres × 1.0936." },
        "note": { "type": ["string", "null"], "description": "Where the target is ('under the big tree')." },
        "direction": { "type": ["number", "null"], "description": "Legacy; ignored by the apps." },
        "inclination": { "type": ["number", "null"], "description": "Legacy; ignored by the apps." }
      }
    },
    "step": {
      "type": "object",
      "required": ["id", "targetID", "rounds"],
      "additionalProperties": false,
      "properties": {
        "id": { "$ref": "#/$defs/uuid" },
        "targetID": { "$ref": "#/$defs/uuid", "description": "The id of a target in the same stage." },
        "rounds": { "type": "integer", "minimum": 1, "description": "Rounds fired at this step." },
        "position": { "type": ["integer", "null"], "minimum": 1, "description": "The shooting position this step is shot from: 1 for the sheet's first position (P1), 2 for the next. Consecutive steps with the same number are one position on the stage card. Omit when the sheet has no positions." },
        "positionNote": { "type": ["string", "null"], "description": "A note for this one engagement only ('kneeling', 'prone'). A position's description goes in the stage's positionNotes." }
      }
    }
  }
}
