{
  "$defs": {
    "Duration": {
      "properties": {
        "type": {
          "$ref": "#/$defs/DurationType"
        },
        "value_sec": {
          "anyOf": [
            {
              "minimum": 0,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "set when type == time",
          "title": "Value Sec"
        },
        "value_m": {
          "anyOf": [
            {
              "minimum": 0,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "set when type == distance",
          "title": "Value M"
        }
      },
      "required": [
        "type"
      ],
      "title": "Duration",
      "type": "object"
    },
    "DurationType": {
      "enum": [
        "time",
        "distance"
      ],
      "title": "DurationType",
      "type": "string"
    },
    "Metric": {
      "enum": [
        "hr",
        "pace",
        "speed",
        "power",
        "rpe"
      ],
      "title": "Metric",
      "type": "string"
    },
    "PlanPhaseDoc": {
      "properties": {
        "id": {
          "maxLength": 50,
          "title": "Id",
          "type": "string"
        },
        "label": {
          "maxLength": 40,
          "title": "Label",
          "type": "string"
        },
        "start_week": {
          "maximum": 520,
          "minimum": 1,
          "title": "Start Week",
          "type": "integer"
        },
        "end_week": {
          "maximum": 520,
          "minimum": 1,
          "title": "End Week",
          "type": "integer"
        },
        "target_weekly_hours": {
          "anyOf": [
            {
              "minimum": 0,
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Target Weekly Hours"
        },
        "focus": {
          "anyOf": [
            {
              "maxLength": 200,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Focus"
        }
      },
      "required": [
        "id",
        "label",
        "start_week",
        "end_week"
      ],
      "title": "PlanPhaseDoc",
      "type": "object"
    },
    "PlannedWorkoutDoc": {
      "properties": {
        "workout_uid": {
          "description": "stable identity across versions (3.7)",
          "maxLength": 100,
          "title": "Workout Uid",
          "type": "string"
        },
        "week_index": {
          "minimum": 1,
          "title": "Week Index",
          "type": "integer"
        },
        "phase_id": {
          "anyOf": [
            {
              "maxLength": 50,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Phase Id"
        },
        "date": {
          "format": "date",
          "title": "Date",
          "type": "string"
        },
        "sport": {
          "$ref": "#/$defs/Sport"
        },
        "title": {
          "maxLength": 200,
          "title": "Title",
          "type": "string"
        },
        "description": {
          "anyOf": [
            {
              "maxLength": 2000,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Description"
        },
        "structure": {
          "$ref": "#/$defs/WorkoutStructure"
        },
        "planned_duration_sec": {
          "anyOf": [
            {
              "minimum": 0,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Planned Duration Sec"
        },
        "planned_distance_m": {
          "anyOf": [
            {
              "minimum": 0,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Planned Distance M"
        },
        "planned_load": {
          "anyOf": [
            {
              "minimum": 0,
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Planned Load"
        },
        "difficulty": {
          "anyOf": [
            {
              "maximum": 10,
              "minimum": 1,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Difficulty"
        },
        "created_by": {
          "anyOf": [
            {
              "enum": [
                "coach",
                "athlete"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": "coach",
          "title": "Created By"
        }
      },
      "required": [
        "workout_uid",
        "week_index",
        "date",
        "sport",
        "title",
        "structure"
      ],
      "title": "PlannedWorkoutDoc",
      "type": "object"
    },
    "Repeat": {
      "properties": {
        "kind": {
          "const": "repeat",
          "default": "repeat",
          "title": "Kind",
          "type": "string"
        },
        "count": {
          "maximum": 50,
          "minimum": 1,
          "title": "Count",
          "type": "integer"
        },
        "steps": {
          "items": {
            "discriminator": {
              "mapping": {
                "repeat": "#/$defs/Repeat",
                "step": "#/$defs/Step"
              },
              "propertyName": "kind"
            },
            "oneOf": [
              {
                "$ref": "#/$defs/Step"
              },
              {
                "$ref": "#/$defs/Repeat"
              }
            ]
          },
          "maxItems": 50,
          "title": "Steps",
          "type": "array"
        }
      },
      "required": [
        "count",
        "steps"
      ],
      "title": "Repeat",
      "type": "object"
    },
    "Sport": {
      "description": "Sports programmables. ``trail`` partage l'essentiel avec ``run`` \u2014 c'est\nde la course \u00e0 pied, m\u00eames zones, m\u00eame hrTSS \u2014 mais ce n'est PAS la m\u00eame\nchose du point de vue du risque :\n\n* le plafond de progression de la sortie longue (+10 % sur 30 jours) est\n  \u00e9tay\u00e9 par une cohorte de COUREURS sur route (BJSM 2024) ; en trail la dur\u00e9e\n  est gonfl\u00e9e par la marche en c\u00f4te et une pr\u00e9pa d'ultra progresse\n  n\u00e9cessairement par sauts plus grands. Il n'y bloque donc pas, il signale ;\n* le facteur limitant du trail est le dommage EXCENTRIQUE de descente\n  (Millet/Giovanelli), pas le volume couru \u2014 et une sortie peut viser le D\u2212\n  plus que le D+, donc le d\u00e9nivel\u00e9 positif seul ne suffirait pas \u00e0 d\u00e9cider.\n\nUn plan MIXE route et trail : c'est pour \u00e7a que la distinction est port\u00e9e par\nla s\u00e9ance et non par le plan.",
      "enum": [
        "run",
        "trail",
        "bike",
        "strength",
        "rest"
      ],
      "title": "Sport",
      "type": "string"
    },
    "Step": {
      "properties": {
        "kind": {
          "const": "step",
          "default": "step",
          "title": "Kind",
          "type": "string"
        },
        "label": {
          "$ref": "#/$defs/StepLabel"
        },
        "duration": {
          "$ref": "#/$defs/Duration"
        },
        "targets": {
          "items": {
            "$ref": "#/$defs/Target"
          },
          "maxItems": 8,
          "title": "Targets",
          "type": "array"
        },
        "note": {
          "anyOf": [
            {
              "maxLength": 500,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Note"
        }
      },
      "required": [
        "label",
        "duration"
      ],
      "title": "Step",
      "type": "object"
    },
    "StepLabel": {
      "enum": [
        "warmup",
        "work",
        "recovery",
        "cooldown",
        "rest",
        "active"
      ],
      "title": "StepLabel",
      "type": "string"
    },
    "Target": {
      "properties": {
        "metric": {
          "$ref": "#/$defs/Metric"
        },
        "mode": {
          "$ref": "#/$defs/TargetMode"
        },
        "zone": {
          "anyOf": [
            {
              "maximum": 7,
              "minimum": 1,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "set when mode == zone",
          "title": "Zone"
        },
        "low": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "set when mode == range",
          "title": "Low"
        },
        "high": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "set when mode == range",
          "title": "High"
        },
        "value": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "set when mode == value",
          "title": "Value"
        }
      },
      "required": [
        "metric",
        "mode"
      ],
      "title": "Target",
      "type": "object"
    },
    "TargetMode": {
      "enum": [
        "zone",
        "range",
        "value"
      ],
      "title": "TargetMode",
      "type": "string"
    },
    "WorkoutStructure": {
      "description": "The `structure` field of a PlannedWorkout \u2014 an ordered list of nodes.",
      "properties": {
        "steps": {
          "items": {
            "discriminator": {
              "mapping": {
                "repeat": "#/$defs/Repeat",
                "step": "#/$defs/Step"
              },
              "propertyName": "kind"
            },
            "oneOf": [
              {
                "$ref": "#/$defs/Step"
              },
              {
                "$ref": "#/$defs/Repeat"
              }
            ]
          },
          "maxItems": 200,
          "title": "Steps",
          "type": "array"
        }
      },
      "required": [
        "steps"
      ],
      "title": "WorkoutStructure",
      "type": "object"
    }
  },
  "description": "A complete plan draft \u2014 the unit your agent produces and the backend\nvalidates against athlete guardrails before storing.",
  "properties": {
    "schema_version": {
      "default": 1,
      "title": "Schema Version",
      "type": "integer"
    },
    "title": {
      "maxLength": 200,
      "title": "Title",
      "type": "string"
    },
    "sport_focus": {
      "enum": [
        "run",
        "bike",
        "multi"
      ],
      "title": "Sport Focus",
      "type": "string"
    },
    "start_date": {
      "format": "date",
      "title": "Start Date",
      "type": "string"
    },
    "end_date": {
      "format": "date",
      "title": "End Date",
      "type": "string"
    },
    "phases": {
      "items": {
        "$ref": "#/$defs/PlanPhaseDoc"
      },
      "maxItems": 30,
      "title": "Phases",
      "type": "array"
    },
    "guidance": {
      "anyOf": [
        {
          "maxLength": 1000,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Guidance"
    },
    "workouts": {
      "items": {
        "$ref": "#/$defs/PlannedWorkoutDoc"
      },
      "maxItems": 1000,
      "title": "Workouts",
      "type": "array"
    }
  },
  "required": [
    "title",
    "sport_focus",
    "start_date",
    "end_date",
    "workouts"
  ],
  "title": "PlanDoc",
  "type": "object",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "x-schema-version": 1
}