{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema0"
        },
        "version": {
          "$ref": "#/$defs/__schema1"
        },
        "subject": {
          "$ref": "#/$defs/__schema1"
        },
        "recordedAt": {
          "$ref": "#/$defs/__schema2"
        },
        "provenance": {
          "$ref": "#/$defs/__schema3"
        },
        "links": {
          "maxItems": 1000,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema7"
          }
        },
        "extensions": {
          "$ref": "#/$defs/__schema8"
        },
        "kind": {
          "type": "string",
          "const": "training.routine"
        },
        "name": {
          "$ref": "#/$defs/__schema1"
        },
        "sport": {
          "$ref": "#/$defs/__schema0"
        },
        "description": {
          "$ref": "#/$defs/__schema1"
        },
        "scheduled": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "instant"
                },
                "at": {
                  "$ref": "#/$defs/__schema2"
                }
              },
              "required": [
                "kind",
                "at"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "interval"
                },
                "start": {
                  "$ref": "#/$defs/__schema2"
                },
                "durationSeconds": {
                  "$ref": "#/$defs/__schema10"
                }
              },
              "required": [
                "kind",
                "start",
                "durationSeconds"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "date"
                },
                "date": {
                  "type": "string",
                  "format": "date",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
                },
                "timezone": {
                  "$ref": "#/$defs/__schema1"
                }
              },
              "required": [
                "kind",
                "date"
              ],
              "additionalProperties": false
            }
          ]
        },
        "structure": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "steps"
                },
                "steps": {
                  "minItems": 1,
                  "maxItems": 1000,
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/__schema11"
                  }
                }
              },
              "required": [
                "kind",
                "steps"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "timeline"
                },
                "durationSeconds": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "maximum": 31536000
                },
                "segments": {
                  "minItems": 1,
                  "maxItems": 1000,
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/__schema17"
                  }
                },
                "cues": {
                  "maxItems": 2000,
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/__schema18"
                  }
                }
              },
              "required": [
                "kind",
                "durationSeconds",
                "segments"
              ],
              "additionalProperties": false
            }
          ]
        }
      },
      "required": [
        "id",
        "version",
        "kind",
        "name",
        "sport",
        "structure"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "revision": {
          "$ref": "#/$defs/__schema19"
        },
        "subject": {
          "$ref": "#/$defs/__schema20"
        },
        "recordedAt": {
          "$ref": "#/$defs/__schema21"
        },
        "provenance": {
          "$ref": "#/$defs/__schema22"
        },
        "links": {
          "$ref": "#/$defs/__schema23"
        },
        "extensions": {
          "$ref": "#/$defs/__schema24"
        },
        "kind": {
          "type": "string",
          "const": "training.workout"
        },
        "sport": {
          "$ref": "#/$defs/__schema0"
        },
        "name": {
          "$ref": "#/$defs/__schema1"
        },
        "interval": {
          "type": "object",
          "properties": {
            "start": {
              "$ref": "#/$defs/__schema2"
            },
            "durationSeconds": {
              "$ref": "#/$defs/__schema10"
            }
          },
          "required": [
            "start",
            "durationSeconds"
          ],
          "additionalProperties": false
        },
        "movingSeconds": {
          "type": "number",
          "minimum": 0
        },
        "routine": {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema0"
            },
            "version": {
              "$ref": "#/$defs/__schema1"
            }
          },
          "required": [
            "id",
            "version"
          ],
          "additionalProperties": false
        },
        "status": {
          "type": "string",
          "enum": [
            "completed",
            "partial",
            "aborted"
          ]
        },
        "metrics": {
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema25"
          }
        },
        "steps": {
          "maxItems": 1000,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema26"
          }
        },
        "sessionRpe": {
          "type": "number",
          "minimum": 0,
          "maximum": 10
        }
      },
      "required": [
        "id",
        "revision",
        "kind",
        "sport",
        "interval"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "revision": {
          "$ref": "#/$defs/__schema19"
        },
        "subject": {
          "$ref": "#/$defs/__schema20"
        },
        "recordedAt": {
          "$ref": "#/$defs/__schema21"
        },
        "provenance": {
          "$ref": "#/$defs/__schema22"
        },
        "links": {
          "$ref": "#/$defs/__schema23"
        },
        "extensions": {
          "$ref": "#/$defs/__schema24"
        },
        "kind": {
          "type": "string",
          "const": "training.threshold"
        },
        "metric": {
          "$ref": "#/$defs/__schema0"
        },
        "quantity": {
          "$ref": "#/$defs/__schema16"
        },
        "effectiveAt": {
          "$ref": "#/$defs/__schema2"
        },
        "method": {
          "type": "string",
          "enum": [
            "tested",
            "estimated"
          ]
        },
        "basis": {
          "$ref": "#/$defs/__schema0"
        },
        "exercise": {
          "$ref": "#/$defs/__schema12"
        }
      },
      "required": [
        "id",
        "revision",
        "kind",
        "metric",
        "quantity",
        "effectiveAt",
        "method"
      ],
      "additionalProperties": false
    }
  ],
  "$defs": {
    "__schema0": {
      "type": "string",
      "maxLength": 256,
      "pattern": "^[a-z][a-z0-9.-]*:[A-Za-z0-9_.-]+$"
    },
    "__schema1": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512
    },
    "__schema2": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "__schema3": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "manual"
            },
            "source": {
              "$ref": "#/$defs/__schema4"
            }
          },
          "required": [
            "kind",
            "source"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "sensor"
            },
            "source": {
              "$ref": "#/$defs/__schema4"
            }
          },
          "required": [
            "kind",
            "source"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "imported"
            },
            "source": {
              "$ref": "#/$defs/__schema4"
            },
            "mapper": {
              "$ref": "#/$defs/__schema5"
            }
          },
          "required": [
            "kind",
            "source",
            "mapper"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "derived"
            },
            "source": {
              "$ref": "#/$defs/__schema4"
            },
            "algorithm": {
              "$ref": "#/$defs/__schema5"
            },
            "inputs": {
              "minItems": 1,
              "maxItems": 1000,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema6"
              }
            }
          },
          "required": [
            "kind",
            "source",
            "algorithm",
            "inputs"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema4": {
      "type": "object",
      "properties": {
        "provider": {
          "$ref": "#/$defs/__schema1"
        },
        "externalId": {
          "$ref": "#/$defs/__schema1"
        },
        "device": {
          "$ref": "#/$defs/__schema1"
        },
        "originalSource": {
          "$ref": "#/$defs/__schema1"
        }
      },
      "required": [
        "provider"
      ],
      "additionalProperties": false
    },
    "__schema5": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema0"
        },
        "version": {
          "$ref": "#/$defs/__schema1"
        }
      },
      "required": [
        "id",
        "version"
      ],
      "additionalProperties": false
    },
    "__schema6": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "revision": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "id",
        "revision"
      ],
      "additionalProperties": false
    },
    "__schema7": {
      "type": "object",
      "properties": {
        "relation": {
          "type": "string",
          "enum": [
            "part_of",
            "same_activity_as",
            "derived_from"
          ]
        },
        "target": {
          "$ref": "#/$defs/__schema6"
        }
      },
      "required": [
        "relation",
        "target"
      ],
      "additionalProperties": false
    },
    "__schema8": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/__schema0"
      },
      "additionalProperties": {
        "$ref": "#/$defs/__schema9"
      }
    },
    "__schema9": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema9"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema9"
          }
        }
      ]
    },
    "__schema10": {
      "type": "number",
      "minimum": 0,
      "maximum": 31536000
    },
    "__schema11": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "exercise": {
          "$ref": "#/$defs/__schema12"
        },
        "role": {
          "$ref": "#/$defs/__schema0"
        },
        "targets": {
          "minItems": 1,
          "maxItems": 20,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema13"
          }
        },
        "load": {
          "$ref": "#/$defs/__schema15"
        },
        "restSeconds": {
          "type": "number",
          "minimum": 0
        },
        "side": {
          "type": "string",
          "enum": [
            "left",
            "right",
            "bilateral"
          ]
        }
      },
      "required": [
        "id",
        "exercise",
        "targets"
      ],
      "additionalProperties": false
    },
    "__schema12": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema0"
        },
        "name": {
          "$ref": "#/$defs/__schema1"
        }
      },
      "required": [
        "id"
      ],
      "additionalProperties": false
    },
    "__schema13": {
      "type": "object",
      "properties": {
        "metric": {
          "$ref": "#/$defs/__schema0"
        },
        "target": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "exact"
                },
                "value": {
                  "$ref": "#/$defs/__schema14"
                },
                "unit": {
                  "$ref": "#/$defs/__schema1"
                }
              },
              "required": [
                "kind",
                "value",
                "unit"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "range"
                },
                "min": {
                  "$ref": "#/$defs/__schema14"
                },
                "max": {
                  "$ref": "#/$defs/__schema14"
                },
                "unit": {
                  "$ref": "#/$defs/__schema1"
                }
              },
              "required": [
                "kind",
                "min",
                "max",
                "unit"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "relative"
                },
                "fraction": {
                  "type": "number",
                  "minimum": 0
                },
                "basis": {
                  "$ref": "#/$defs/__schema0"
                },
                "threshold": {
                  "$ref": "#/$defs/__schema6"
                }
              },
              "required": [
                "kind",
                "fraction"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "ramp"
                },
                "start": {
                  "$ref": "#/$defs/__schema14"
                },
                "end": {
                  "$ref": "#/$defs/__schema14"
                },
                "unit": {
                  "$ref": "#/$defs/__schema1"
                },
                "basis": {
                  "$ref": "#/$defs/__schema0"
                },
                "threshold": {
                  "$ref": "#/$defs/__schema6"
                },
                "interpolation": {
                  "type": "string",
                  "enum": [
                    "linear",
                    "step"
                  ]
                }
              },
              "required": [
                "kind",
                "start",
                "end",
                "unit"
              ],
              "additionalProperties": false
            }
          ]
        }
      },
      "required": [
        "metric",
        "target"
      ],
      "additionalProperties": false
    },
    "__schema14": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "string",
          "maxLength": 100,
          "pattern": "^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?$"
        }
      ]
    },
    "__schema15": {
      "type": "object",
      "properties": {
        "basis": {
          "type": "string",
          "enum": [
            "external_total",
            "external_per_hand",
            "added",
            "assisted",
            "bodyweight_fraction"
          ]
        },
        "amount": {
          "$ref": "#/$defs/__schema16"
        }
      },
      "required": [
        "basis",
        "amount"
      ],
      "additionalProperties": false
    },
    "__schema16": {
      "type": "object",
      "properties": {
        "value": {
          "$ref": "#/$defs/__schema14"
        },
        "unit": {
          "$ref": "#/$defs/__schema1"
        }
      },
      "required": [
        "value",
        "unit"
      ],
      "additionalProperties": false
    },
    "__schema17": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "startSeconds": {
          "type": "number",
          "minimum": 0
        },
        "endSeconds": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "label": {
          "$ref": "#/$defs/__schema1"
        },
        "role": {
          "$ref": "#/$defs/__schema0"
        },
        "targets": {
          "minItems": 1,
          "maxItems": 20,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema13"
          }
        }
      },
      "required": [
        "id",
        "startSeconds",
        "endSeconds",
        "targets"
      ],
      "additionalProperties": false
    },
    "__schema18": {
      "type": "object",
      "properties": {
        "atSeconds": {
          "type": "number",
          "minimum": 0
        },
        "posture": {
          "$ref": "#/$defs/__schema1"
        },
        "resistance": {
          "$ref": "#/$defs/__schema1"
        },
        "text": {
          "$ref": "#/$defs/__schema1"
        }
      },
      "required": [
        "atSeconds"
      ],
      "additionalProperties": false
    },
    "__schema19": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "__schema20": {
      "$ref": "#/$defs/__schema1"
    },
    "__schema21": {
      "$ref": "#/$defs/__schema2"
    },
    "__schema22": {
      "$ref": "#/$defs/__schema3"
    },
    "__schema23": {
      "maxItems": 1000,
      "type": "array",
      "items": {
        "$ref": "#/$defs/__schema7"
      }
    },
    "__schema24": {
      "$ref": "#/$defs/__schema8"
    },
    "__schema25": {
      "type": "object",
      "properties": {
        "metric": {
          "$ref": "#/$defs/__schema0"
        },
        "value": {
          "$ref": "#/$defs/__schema14"
        },
        "unit": {
          "$ref": "#/$defs/__schema1"
        }
      },
      "required": [
        "metric",
        "value",
        "unit"
      ],
      "additionalProperties": false
    },
    "__schema26": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "exercise": {
          "$ref": "#/$defs/__schema12"
        },
        "plannedStepId": {
          "$ref": "#/$defs/__schema1"
        },
        "role": {
          "$ref": "#/$defs/__schema0"
        },
        "side": {
          "type": "string",
          "enum": [
            "left",
            "right",
            "bilateral"
          ]
        },
        "result": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "enum": [
                    "completed",
                    "partial"
                  ]
                },
                "metrics": {
                  "minItems": 1,
                  "maxItems": 20,
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/__schema25"
                  }
                },
                "load": {
                  "$ref": "#/$defs/__schema15"
                },
                "rpe": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 10
                }
              },
              "required": [
                "kind",
                "metrics"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "skipped"
                },
                "reason": {
                  "$ref": "#/$defs/__schema1"
                }
              },
              "required": [
                "kind",
                "reason"
              ],
              "additionalProperties": false
            }
          ]
        }
      },
      "required": [
        "id",
        "exercise",
        "result"
      ],
      "additionalProperties": false
    }
  },
  "title": "FitData training schema",
  "description": "Structural schema for FitData domain records. Also run semantic and document reference validation."
}
