{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "VYRO · Programme sportif v2",
  "description": "Utiliser des identifiants d’entités uniques dans tout le programme, des jours ISO et un nombre entier de longueurs par répétition de natation.",
  "type": "object",
  "required": [
    "schemaVersion",
    "id",
    "title",
    "language",
    "cycles"
  ],
  "properties": {
    "schemaVersion": {
      "type": "integer",
      "const": 2
    },
    "id": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_.-]{1,128}$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "\\S"
    },
    "description": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "author": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "language": {
      "type": "string",
      "pattern": "^[A-Za-z]{2,3}(-[A-Za-z]{2})?$"
    },
    "objectives": {
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 0
        },
        {
          "type": "null"
        }
      ]
    },
    "level": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "prerequisites": {
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 0
        },
        {
          "type": "null"
        }
      ]
    },
    "progression": {
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 0
        },
        {
          "type": "null"
        }
      ]
    },
    "catalogVersion": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000
        },
        {
          "type": "null"
        }
      ]
    },
    "preferredWeekdays": {
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 1,
            "maximum": 7
          },
          "minItems": 0,
          "maxItems": 7,
          "uniqueItems": true
        },
        {
          "type": "null"
        }
      ]
    },
    "cycles": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/cycle"
      },
      "minItems": 1,
      "maxItems": 156
    }
  },
  "$defs": {
    "cycle": {
      "type": "object",
      "required": [
        "id",
        "title",
        "weeks"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.-]{1,128}$"
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160,
          "pattern": "\\S"
        },
        "weeks": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/week"
          },
          "minItems": 1,
          "maxItems": 156
        }
      }
    },
    "week": {
      "type": "object",
      "required": [
        "id",
        "sessions"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.-]{1,128}$"
        },
        "title": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "sessions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/session"
          },
          "minItems": 0,
          "maxItems": 28
        }
      }
    },
    "session": {
      "type": "object",
      "required": [
        "id",
        "title",
        "weekday",
        "blocks"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.-]{1,128}$"
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160,
          "pattern": "\\S"
        },
        "weekday": {
          "type": "integer",
          "minimum": 1,
          "maximum": 7
        },
        "minutes": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 1440
            },
            {
              "type": "null"
            }
          ]
        },
        "instructions": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "blocks": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/block"
          },
          "minItems": 1,
          "maxItems": 32
        }
      }
    },
    "block": {
      "type": "object",
      "required": [
        "id",
        "kind",
        "title"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.-]{1,128}$"
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160,
          "pattern": "\\S"
        },
        "kind": {
          "enum": [
            "strength",
            "swimming",
            "transition",
            "cardio",
            "mobility"
          ]
        },
        "minutes": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 1440
            },
            {
              "type": "null"
            }
          ]
        },
        "instructions": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "exerciseID": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9_.-]{1,128}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "exercises": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/exercise"
              },
              "minItems": 1,
              "maxItems": 60
            },
            {
              "type": "null"
            }
          ]
        },
        "pool": {
          "anyOf": [
            {
              "$ref": "#/$defs/distance"
            },
            {
              "type": "null"
            }
          ]
        },
        "intervals": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/interval"
              },
              "minItems": 1,
              "maxItems": 60
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "strength"
              }
            }
          },
          "then": {
            "required": [
              "exercises"
            ],
            "properties": {
              "exercises": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/exercise"
                },
                "minItems": 1,
                "maxItems": 60
              },
              "pool": {
                "type": "null"
              },
              "intervals": {
                "type": "null"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "swimming"
              }
            }
          },
          "then": {
            "required": [
              "pool",
              "intervals"
            ],
            "properties": {
              "exercises": {
                "type": "null"
              },
              "pool": {
                "allOf": [
                  {
                    "$ref": "#/$defs/distance"
                  },
                  {
                    "if": {
                      "properties": {
                        "unit": {
                          "const": "m"
                        }
                      }
                    },
                    "then": {
                      "properties": {
                        "value": {
                          "type": "number",
                          "minimum": 1,
                          "maximum": 200
                        }
                      }
                    },
                    "else": {
                      "properties": {
                        "value": {
                          "type": "number",
                          "minimum": 1.0936132983377078,
                          "maximum": 218.72265966754156
                        }
                      }
                    }
                  }
                ]
              },
              "intervals": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/interval"
                },
                "minItems": 1,
                "maxItems": 60
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "enum": [
                  "transition",
                  "cardio",
                  "mobility"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "exercises": {
                "type": "null"
              },
              "pool": {
                "type": "null"
              },
              "intervals": {
                "type": "null"
              }
            }
          }
        }
      ]
    },
    "exercise": {
      "type": "object",
      "required": [
        "id",
        "exerciseID",
        "name",
        "sets",
        "repsMin",
        "repsMax",
        "restSeconds"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.-]{1,128}$"
        },
        "exerciseID": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.-]{1,128}$"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160,
          "pattern": "\\S"
        },
        "sets": {
          "type": "integer",
          "minimum": 1,
          "maximum": 50
        },
        "repsMin": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000
        },
        "repsMax": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000
        },
        "restSeconds": {
          "type": "integer",
          "minimum": 0,
          "maximum": 3600
        },
        "loadKg": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0,
              "maximum": 2000
            },
            {
              "type": "null"
            }
          ]
        },
        "equipmentID": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9_.-]{1,128}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "timerSeconds": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 14400
            },
            {
              "type": "null"
            }
          ]
        },
        "loadKind": {
          "anyOf": [
            {
              "enum": [
                "external",
                "bodyweight",
                "added",
                "assistance",
                "unquantified"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "loadRecommendation": {
          "anyOf": [
            {
              "type": "object",
              "required": [
                "method"
              ],
              "properties": {
                "method": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 160,
                  "pattern": "\\S"
                },
                "minimum": {
                  "anyOf": [
                    {
                      "type": "number",
                      "minimum": 0,
                      "maximum": 2000
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "maximum": {
                  "anyOf": [
                    {
                      "type": "number",
                      "minimum": 0,
                      "maximum": 2000
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "unit": {
                  "anyOf": [
                    {
                      "enum": [
                        "kg",
                        "lb"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "rpe": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0,
              "maximum": 10
            },
            {
              "type": "null"
            }
          ]
        },
        "rir": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 50
            },
            {
              "type": "null"
            }
          ]
        },
        "tempo": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "alternatives": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_.-]{1,128}$"
              },
              "minItems": 0
            },
            {
              "type": "null"
            }
          ]
        },
        "instructions": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "distance": {
      "type": "object",
      "required": [
        "value",
        "unit"
      ],
      "properties": {
        "value": {
          "type": "number"
        },
        "unit": {
          "enum": [
            "m",
            "yd"
          ]
        }
      },
      "if": {
        "properties": {
          "unit": {
            "const": "m"
          }
        }
      },
      "then": {
        "properties": {
          "value": {
            "type": "number",
            "minimum": 1,
            "maximum": 10000
          }
        }
      },
      "else": {
        "properties": {
          "value": {
            "type": "number",
            "minimum": 1.0936132983377078,
            "maximum": 10936.132983377078
          }
        }
      }
    },
    "interval": {
      "type": "object",
      "required": [
        "id",
        "stage",
        "distance",
        "repetitions",
        "stroke",
        "restSeconds"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.-]{1,128}$"
        },
        "stage": {
          "enum": [
            "warmup",
            "technique",
            "main",
            "recovery",
            "cooldown"
          ]
        },
        "distance": {
          "$ref": "#/$defs/distance"
        },
        "repetitions": {
          "type": "integer",
          "minimum": 1,
          "maximum": 200
        },
        "stroke": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160,
          "pattern": "\\S"
        },
        "restSeconds": {
          "type": "integer",
          "minimum": 0,
          "maximum": 3600
        },
        "exerciseID": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9_.-]{1,128}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "targetSeconds": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 14400
            },
            {
              "type": "null"
            }
          ]
        },
        "intensity": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "equipment": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 0
            },
            {
              "type": "null"
            }
          ]
        },
        "instructions": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    }
  }
}
