{
  "openapi": "3.1.0",
  "info": {
    "title": "SwollStep Agent API",
    "version": "1.0.0",
    "description": "Creation-only Program API. Bearer tokens are created in the SwollStep app under Settings → Agent API. Read /v1/catalog to resolve owned exercise/workout UUIDs. POST /v1/programs requires Idempotency-Key and creates normalized database rows transactionally; 201 means created and immediately readable. The app downloads changes on sync. GET /v1/programs/{id} accepts a native Program ID. Use /v1/operations/{id} for creation receipts. Unknown/result/owner fields are rejected. Dates are floating and inclusive, with Sunday=1; the maximum range is 366 days. Every attached reps/duration/distance/pace/effort/stroke field requires its target. Load requires load_type, and externalWeight requires weight_lb (pounds). Rounds cannot combine with duration; repetition cannot combine with rounds or intervals; untilDuration and intervals require duration. Interval duration must be evenly divisible by interval_seconds, with at most 1,000 intervals. Rest between rounds requires rounds or untilDuration. Weekly rules accept changes with effective_date and per-step target patches. Patches accumulate chronologically, retaining previous targets when omitted. A step reference is an optional key declared on a new step or an existing catalogue step UUID. Changes apply only to that rule from their date onward; the library base remains unchanged. No automatic performance-based progression is inferred. Request limit 1 MiB; expanded schedule limit 5 MiB; 30 creations/minute/token. Retry the identical request with the same token/key to retain IDs. Public specification: /openapi.json. POST /v1/workouts creates workout definitions only, with no Program or dates. It uses the same Idempotency-Key and direct database creation flow. GET /v1/workouts/{workout-id} returns the saved definition; GET /v1/operations/{receipt-id} returns the creation receipt. Workout duration_progression_seconds is a reference plan, not an automatic schedule. Programs may be unscheduled: omit both start_date/end_date to save a draft and generate no entries. Draft changes use week (1–52) instead of effective_date; scheduling later anchors weeks to start_date. Weekly progression belongs to Program rules, not exercise definitions or library workouts. Training data is authoritative in typed normalized tables. Account snapshot and import-queue tables have been removed. Tokens remain read-catalogue/create-only; they cannot edit results. Relative plans use week_count and seven relative_days (day 1–7), without rules or dates. Each expanded week and day has a stable ID and independent prescription. Changes must use week within week_count. Optional workouts may declare rest_alternative; rest-only days omit workout and require rest_alternative=true. No dates or entries are created for these drafts. RRULE parsing is not implemented."
  },
  "servers": [
    {
      "url": "https://fvgemdcvjuknvzdqkurt.supabase.co/functions/v1/agent-api",
      "description": "Hosted Supabase"
    },
    {
      "url": "http://127.0.0.1:55321/functions/v1/agent-api",
      "description": "Local development"
    }
  ],
  "security": [
    {
      "agentToken": []
    }
  ],
  "paths": {
    "/v1/catalog": {
      "get": {
        "operationId": "getCatalog",
        "responses": {
          "200": {
            "description": "Latest uploaded catalogue; excludes history",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "include_archived",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Include owned archived definitions for inspection/reuse."
          }
        ]
      }
    },
    "/v1/programs": {
      "post": {
        "operationId": "createProgram",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateProgram"
              },
              "examples": {
                "fixed": {
                  "summary": "Fixed targets",
                  "value": {
                    "exercises": [
                      {
                        "key": "bench",
                        "name": "Bench press",
                        "fields": [
                          "load",
                          "reps",
                          "rest"
                        ]
                      },
                      {
                        "key": "walk",
                        "name": "Brisk walk",
                        "fields": [
                          "duration"
                        ]
                      }
                    ],
                    "workouts": [
                      {
                        "key": "strength",
                        "title": "Strength day",
                        "color": "blue",
                        "blocks": [
                          {
                            "title": "Warm-up",
                            "items": [
                              {
                                "exercise": "walk",
                                "targets": {
                                  "duration_seconds": 300
                                }
                              }
                            ]
                          },
                          {
                            "title": "Bench press",
                            "items": [
                              {
                                "title": "Ramp-up",
                                "exercises": [
                                  {
                                    "exercise": "bench",
                                    "targets": {
                                      "load_type": "externalWeight",
                                      "weight_lb": 45,
                                      "reps": 10,
                                      "rest_seconds": 60
                                    }
                                  },
                                  {
                                    "exercise": "bench",
                                    "targets": {
                                      "load_type": "externalWeight",
                                      "weight_lb": 95,
                                      "reps": 5,
                                      "rest_seconds": 60
                                    }
                                  }
                                ]
                              },
                              {
                                "title": "Working sets",
                                "fields": {
                                  "rounds": 3
                                },
                                "exercises": [
                                  {
                                    "exercise": "bench",
                                    "targets": {
                                      "load_type": "externalWeight",
                                      "weight_lb": 140,
                                      "reps": 8,
                                      "rest_seconds": 90
                                    }
                                  }
                                ]
                              }
                            ]
                          }
                        ]
                      }
                    ],
                    "program": {
                      "title": "Three-day strength",
                      "start_date": "2026-10-13",
                      "end_date": "2026-11-13",
                      "rules": [
                        {
                          "weekday": 2,
                          "workout": "strength"
                        },
                        {
                          "weekday": 4,
                          "workout": "strength"
                        },
                        {
                          "weekday": 6,
                          "workout": "strength"
                        }
                      ]
                    }
                  }
                },
                "progression": {
                  "summary": "One workout with dated bench progression",
                  "value": {
                    "exercises": [
                      {
                        "key": "bench",
                        "name": "Bench press",
                        "fields": [
                          "load",
                          "reps",
                          "rest"
                        ]
                      },
                      {
                        "key": "walk",
                        "name": "Brisk walk",
                        "fields": [
                          "duration"
                        ]
                      }
                    ],
                    "workouts": [
                      {
                        "key": "strength",
                        "title": "Strength day",
                        "color": "blue",
                        "blocks": [
                          {
                            "title": "Warm-up",
                            "items": [
                              {
                                "exercise": "walk",
                                "targets": {
                                  "duration_seconds": 300
                                }
                              }
                            ]
                          },
                          {
                            "title": "Bench press",
                            "items": [
                              {
                                "title": "Ramp-up",
                                "exercises": [
                                  {
                                    "exercise": "bench",
                                    "targets": {
                                      "load_type": "externalWeight",
                                      "weight_lb": 45,
                                      "reps": 10,
                                      "rest_seconds": 60
                                    }
                                  },
                                  {
                                    "exercise": "bench",
                                    "targets": {
                                      "load_type": "externalWeight",
                                      "weight_lb": 95,
                                      "reps": 5,
                                      "rest_seconds": 60
                                    }
                                  }
                                ]
                              },
                              {
                                "title": "Working sets",
                                "fields": {
                                  "rounds": 3
                                },
                                "exercises": [
                                  {
                                    "exercise": "bench",
                                    "targets": {
                                      "load_type": "externalWeight",
                                      "weight_lb": 140,
                                      "reps": 8,
                                      "rest_seconds": 90
                                    },
                                    "key": "working_bench"
                                  }
                                ]
                              }
                            ]
                          }
                        ]
                      }
                    ],
                    "program": {
                      "title": "Progressive strength",
                      "start_date": "2026-10-12",
                      "end_date": "2026-11-08",
                      "rules": [
                        {
                          "weekday": 2,
                          "workout": "strength",
                          "changes": [
                            {
                              "effective_date": "2026-10-19",
                              "targets": [
                                {
                                  "step": "working_bench",
                                  "targets": {
                                    "weight_lb": 145
                                  }
                                }
                              ]
                            },
                            {
                              "effective_date": "2026-11-02",
                              "targets": [
                                {
                                  "step": "working_bench",
                                  "targets": {
                                    "weight_lb": 150
                                  }
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "weekday": 4,
                          "workout": "strength",
                          "changes": [
                            {
                              "effective_date": "2026-10-19",
                              "targets": [
                                {
                                  "step": "working_bench",
                                  "targets": {
                                    "weight_lb": 145
                                  }
                                }
                              ]
                            },
                            {
                              "effective_date": "2026-11-02",
                              "targets": [
                                {
                                  "step": "working_bench",
                                  "targets": {
                                    "weight_lb": 150
                                  }
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "weekday": 6,
                          "workout": "strength",
                          "changes": [
                            {
                              "effective_date": "2026-10-19",
                              "targets": [
                                {
                                  "step": "working_bench",
                                  "targets": {
                                    "weight_lb": 145
                                  }
                                }
                              ]
                            },
                            {
                              "effective_date": "2026-11-02",
                              "targets": [
                                {
                                  "step": "working_bench",
                                  "targets": {
                                    "weight_lb": 150
                                  }
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created atomically in normalized tables; immediately readable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "400": {
            "description": "Missing/invalid idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Unsupported content type",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid prescription",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limit reached",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/programs/{id}": {
      "get": {
        "operationId": "getProgram",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Native Program UUID"
          }
        ],
        "responses": {
          "200": {
            "description": "Import receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Native Program definition with ordered rules and progression."
                }
              }
            }
          },
          "401": {
            "description": "Invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "operationId": "getOpenAPISpec",
        "security": [],
        "summary": "Public OpenAPI specification; no token required",
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 document",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workouts": {
      "post": {
        "operationId": "createWorkouts",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWorkouts"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created atomically in normalized tables; immediately readable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "400": {
            "description": "Missing/invalid idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Unsupported content type",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid prescription",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limit reached",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/operations/{id}": {
      "get": {
        "operationId": "getCreationOperation",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Import receipt ID returned by POST, not the native Program ID."
          }
        ],
        "responses": {
          "200": {
            "description": "Import receipt plus canonical workouts and exercise definitions",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Receipt"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "workouts": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "exercises": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workouts/{id}": {
      "get": {
        "operationId": "getWorkout",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Native workout UUID"
          }
        ],
        "responses": {
          "200": {
            "description": "Import receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Native Codable workout prescription with ordered blocks/groups/steps."
                }
              }
            }
          },
          "401": {
            "description": "Invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "agentToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "swollstep_ + 64 lowercase hex characters"
      }
    },
    "schemas": {
      "CreateProgram": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "exercises": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "key": {
                  "type": "string",
                  "pattern": "^[a-zA-Z][a-zA-Z0-9_-]*$",
                  "maxLength": 80
                },
                "name": {
                  "type": "string",
                  "maxLength": 200,
                  "minLength": 1
                },
                "fields": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "load",
                      "reps",
                      "duration",
                      "distance",
                      "pace",
                      "effort",
                      "stroke",
                      "rest",
                      "repsInReserve",
                      "equipment"
                    ]
                  },
                  "minItems": 1,
                  "maxItems": 10,
                  "uniqueItems": true
                },
                "distance_unit": {
                  "type": "string",
                  "enum": [
                    "meters",
                    "kilometers",
                    "miles",
                    "yards"
                  ]
                },
                "pace_unit": {
                  "type": "string",
                  "enum": [
                    "perKilometer",
                    "perMile",
                    "per100Meters",
                    "per100Yards"
                  ]
                }
              },
              "required": [
                "key",
                "name",
                "fields"
              ]
            },
            "minItems": 0,
            "maxItems": 200
          },
          "workouts": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "key": {
                  "type": "string",
                  "pattern": "^[a-zA-Z][a-zA-Z0-9_-]*$",
                  "maxLength": 80
                },
                "title": {
                  "type": "string",
                  "maxLength": 200
                },
                "color": {
                  "type": "string",
                  "enum": [
                    "indigo",
                    "blue",
                    "green",
                    "orange",
                    "pink",
                    "purple"
                  ]
                },
                "blocks": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "title": {
                        "type": "string",
                        "maxLength": 200
                      },
                      "labels": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 80
                        },
                        "minItems": 0,
                        "maxItems": 20
                      },
                      "items": {
                        "type": "array",
                        "items": {
                          "oneOf": [
                            {
                              "$ref": "#/components/schemas/Step"
                            },
                            {
                              "$ref": "#/components/schemas/Group"
                            }
                          ]
                        },
                        "minItems": 1,
                        "maxItems": 100
                      }
                    },
                    "required": [
                      "items"
                    ]
                  },
                  "minItems": 1,
                  "maxItems": 50
                },
                "description": {
                  "type": "string",
                  "maxLength": 4000
                },
                "labels": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "maxItems": 20
                },
                "estimated_duration_seconds": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 86400
                },
                "duration_progression_seconds": {
                  "type": "array",
                  "minItems": 1,
                  "maxItems": 52,
                  "items": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 86400
                  },
                  "description": "Ordered reference duration targets, typically one per week. Does not create dates, Programs or schedule entries."
                }
              },
              "required": [
                "key",
                "blocks"
              ]
            },
            "minItems": 0,
            "maxItems": 50
          },
          "program": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "title": {
                "type": "string",
                "maxLength": 200
              },
              "start_date": {
                "type": "string",
                "format": "date",
                "description": "Optional. Provide both start_date and end_date only when scheduling."
              },
              "end_date": {
                "type": "string",
                "format": "date",
                "description": "Optional. Omit both dates for an unscheduled Program."
              },
              "rules": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "weekday": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 7,
                      "description": "Sunday=1 through Saturday=7"
                    },
                    "workout": {
                      "type": "string",
                      "maxLength": 80,
                      "description": "New workout key or available catalogue UUID"
                    },
                    "changes": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "targets"
                        ],
                        "properties": {
                          "effective_date": {
                            "type": "string",
                            "format": "date",
                            "description": "Unique effective date within the Program range. Changes accumulate in chronological order."
                          },
                          "targets": {
                            "type": "array",
                            "minItems": 1,
                            "maxItems": 1000,
                            "items": {
                              "type": "object",
                              "additionalProperties": false,
                              "required": [
                                "step",
                                "targets"
                              ],
                              "properties": {
                                "step": {
                                  "type": "string",
                                  "maxLength": 80,
                                  "description": "Step key declared on this workout or existing catalogue step UUID."
                                },
                                "targets": {
                                  "$ref": "#/components/schemas/TargetPatch"
                                }
                              }
                            }
                          },
                          "week": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 52,
                            "description": "Program-relative week. Works without calendar dates."
                          }
                        },
                        "oneOf": [
                          {
                            "required": [
                              "week"
                            ],
                            "not": {
                              "required": [
                                "effective_date"
                              ]
                            }
                          },
                          {
                            "required": [
                              "effective_date"
                            ],
                            "not": {
                              "required": [
                                "week"
                              ]
                            }
                          }
                        ]
                      }
                    }
                  },
                  "required": [
                    "weekday",
                    "workout"
                  ]
                },
                "minItems": 1,
                "maxItems": 40
              },
              "description": {
                "type": "string",
                "maxLength": 4000
              },
              "week_count": {
                "type": "integer",
                "minimum": 1,
                "maximum": 52
              },
              "relative_days": {
                "type": "array",
                "minItems": 7,
                "maxItems": 7,
                "description": "Unscheduled relative plan: each Day 1–7 exactly once. Expands into week_count weeks with independent prescriptions. Mutually exclusive with rules and dates.",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "day"
                  ],
                  "properties": {
                    "day": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 7
                    },
                    "workout": {
                      "type": "string",
                      "maxLength": 80
                    },
                    "optional": {
                      "type": "boolean"
                    },
                    "rest_alternative": {
                      "type": "boolean"
                    },
                    "notes": {
                      "type": "string",
                      "maxLength": 4000
                    },
                    "changes": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "targets"
                        ],
                        "properties": {
                          "effective_date": {
                            "type": "string",
                            "format": "date",
                            "description": "Unique effective date within the Program range. Changes accumulate in chronological order."
                          },
                          "targets": {
                            "type": "array",
                            "minItems": 1,
                            "maxItems": 1000,
                            "items": {
                              "type": "object",
                              "additionalProperties": false,
                              "required": [
                                "step",
                                "targets"
                              ],
                              "properties": {
                                "step": {
                                  "type": "string",
                                  "maxLength": 80,
                                  "description": "Step key declared on this workout or existing catalogue step UUID."
                                },
                                "targets": {
                                  "$ref": "#/components/schemas/TargetPatch"
                                }
                              }
                            }
                          },
                          "week": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 52,
                            "description": "Program-relative week. Works without calendar dates."
                          }
                        },
                        "oneOf": [
                          {
                            "required": [
                              "week"
                            ],
                            "not": {
                              "required": [
                                "effective_date"
                              ]
                            }
                          },
                          {
                            "required": [
                              "effective_date"
                            ],
                            "not": {
                              "required": [
                                "week"
                              ]
                            }
                          }
                        ]
                      }
                    }
                  }
                }
              }
            },
            "required": [],
            "oneOf": [
              {
                "required": [
                  "rules"
                ],
                "not": {
                  "required": [
                    "relative_days"
                  ]
                }
              },
              {
                "required": [
                  "relative_days",
                  "week_count"
                ],
                "not": {
                  "anyOf": [
                    {
                      "required": [
                        "rules"
                      ]
                    },
                    {
                      "required": [
                        "start_date"
                      ]
                    },
                    {
                      "required": [
                        "end_date"
                      ]
                    }
                  ]
                }
              }
            ]
          }
        },
        "required": [
          "program"
        ]
      },
      "Targets": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "load_type": {
            "type": "string",
            "enum": [
              "bodyweight",
              "externalWeight",
              "none"
            ]
          },
          "weight_lb": {
            "type": "number",
            "minimum": 0,
            "maximum": 10000
          },
          "reps": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000
          },
          "rep_scope": {
            "type": "string",
            "enum": [
              "total",
              "perSide",
              "perDirection"
            ]
          },
          "weight_basis": {
            "type": "string",
            "enum": [
              "total",
              "perDumbbell"
            ]
          },
          "duration_seconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 86400
          },
          "distance": {
            "type": "number",
            "minimum": 0.000001,
            "maximum": 1000000
          },
          "pace_seconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 86400
          },
          "effort": {
            "type": "string",
            "enum": [
              "easy",
              "moderate",
              "hard",
              "maximal"
            ]
          },
          "stroke": {
            "type": "string",
            "enum": [
              "freestyle",
              "backstroke",
              "breaststroke",
              "butterfly",
              "mixed"
            ]
          },
          "rest_seconds": {
            "type": "integer",
            "minimum": 0,
            "maximum": 86400
          },
          "reps_in_reserve": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "equipment": {
            "type": "string",
            "maxLength": 200
          }
        }
      },
      "Step": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "exercise": {
            "type": "string",
            "maxLength": 80,
            "description": "New exercise key or available catalogue UUID."
          },
          "title": {
            "type": "string",
            "maxLength": 200
          },
          "labels": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            },
            "minItems": 0,
            "maxItems": 20
          },
          "instructions": {
            "type": "string",
            "maxLength": 2000
          },
          "targets": {
            "$ref": "#/components/schemas/Targets"
          },
          "key": {
            "type": "string",
            "pattern": "^[a-zA-Z][a-zA-Z0-9_-]*$",
            "maxLength": 80,
            "description": "Optional unique step key within a workout, used by dated target changes."
          },
          "record_only_fields": {
            "type": "array",
            "maxItems": 6,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "enum": [
                "reps",
                "duration",
                "distance",
                "pace",
                "effort",
                "stroke"
              ]
            },
            "description": "Attached measurements to record without requiring a prescribed target. Actual results remain empty until performed."
          }
        },
        "required": [
          "exercise",
          "targets"
        ]
      },
      "Group": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 200
          },
          "labels": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            },
            "minItems": 0,
            "maxItems": 20
          },
          "fields": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "rounds": {
                "type": "integer",
                "minimum": 1,
                "maximum": 100
              },
              "duration_seconds": {
                "type": "integer",
                "minimum": 1,
                "maximum": 86400
              },
              "interval_seconds": {
                "type": "integer",
                "minimum": 1,
                "maximum": 86400
              },
              "rest_between_rounds_seconds": {
                "type": "integer",
                "minimum": 0,
                "maximum": 86400
              },
              "repetition": {
                "type": "string",
                "enum": [
                  "once",
                  "untilDuration"
                ]
              },
              "tracks_rounds": {
                "type": "boolean"
              }
            }
          },
          "exercises": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Step"
            },
            "minItems": 1,
            "maxItems": 100
          }
        },
        "required": [
          "exercises"
        ]
      },
      "Receipt": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Creation operation ID; use /v1/operations/{id} for its receipt."
          },
          "status": {
            "type": "string",
            "enum": [
              "created"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "programs": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "title": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "title"
              ]
            },
            "minItems": 0,
            "maxItems": 100
          },
          "workout_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "minItems": 0,
            "maxItems": 100
          }
        },
        "required": [
          "id",
          "status",
          "created_at",
          "programs",
          "workout_ids"
        ]
      },
      "Error": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "TargetPatch": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "load_type": {
            "type": "string",
            "enum": [
              "bodyweight",
              "externalWeight",
              "none"
            ]
          },
          "weight_lb": {
            "type": "number",
            "minimum": 0,
            "maximum": 10000
          },
          "reps": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000
          },
          "rep_scope": {
            "type": "string",
            "enum": [
              "total",
              "perSide",
              "perDirection"
            ]
          },
          "weight_basis": {
            "type": "string",
            "enum": [
              "total",
              "perDumbbell"
            ]
          },
          "duration_seconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 86400
          },
          "distance": {
            "type": "number",
            "minimum": 0.000001,
            "maximum": 1000000
          },
          "pace_seconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 86400
          },
          "effort": {
            "type": "string",
            "enum": [
              "easy",
              "moderate",
              "hard",
              "maximal"
            ]
          },
          "stroke": {
            "type": "string",
            "enum": [
              "freestyle",
              "backstroke",
              "breaststroke",
              "butterfly",
              "mixed"
            ]
          },
          "rest_seconds": {
            "type": "integer",
            "minimum": 0,
            "maximum": 86400
          },
          "reps_in_reserve": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "equipment": {
            "type": "string",
            "maxLength": 200
          }
        },
        "minProperties": 1,
        "description": "Partial target changes; omitted targets retain their previous value. Only attached fields may change. load_type=bodyweight/none clears an omitted external weight."
      },
      "CreateWorkouts": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "workouts"
        ],
        "properties": {
          "exercises": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "key": {
                  "type": "string",
                  "pattern": "^[a-zA-Z][a-zA-Z0-9_-]*$",
                  "maxLength": 80
                },
                "name": {
                  "type": "string",
                  "maxLength": 200,
                  "minLength": 1
                },
                "fields": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "load",
                      "reps",
                      "duration",
                      "distance",
                      "pace",
                      "effort",
                      "stroke",
                      "rest",
                      "repsInReserve",
                      "equipment"
                    ]
                  },
                  "minItems": 1,
                  "maxItems": 10,
                  "uniqueItems": true
                },
                "distance_unit": {
                  "type": "string",
                  "enum": [
                    "meters",
                    "kilometers",
                    "miles",
                    "yards"
                  ]
                },
                "pace_unit": {
                  "type": "string",
                  "enum": [
                    "perKilometer",
                    "perMile",
                    "per100Meters",
                    "per100Yards"
                  ]
                }
              },
              "required": [
                "key",
                "name",
                "fields"
              ]
            },
            "minItems": 0,
            "maxItems": 200
          },
          "workouts": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "key": {
                  "type": "string",
                  "pattern": "^[a-zA-Z][a-zA-Z0-9_-]*$",
                  "maxLength": 80
                },
                "title": {
                  "type": "string",
                  "maxLength": 200
                },
                "color": {
                  "type": "string",
                  "enum": [
                    "indigo",
                    "blue",
                    "green",
                    "orange",
                    "pink",
                    "purple"
                  ]
                },
                "blocks": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "title": {
                        "type": "string",
                        "maxLength": 200
                      },
                      "labels": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 80
                        },
                        "minItems": 0,
                        "maxItems": 20
                      },
                      "items": {
                        "type": "array",
                        "items": {
                          "oneOf": [
                            {
                              "$ref": "#/components/schemas/Step"
                            },
                            {
                              "$ref": "#/components/schemas/Group"
                            }
                          ]
                        },
                        "minItems": 1,
                        "maxItems": 100
                      }
                    },
                    "required": [
                      "items"
                    ]
                  },
                  "minItems": 1,
                  "maxItems": 50
                },
                "description": {
                  "type": "string",
                  "maxLength": 4000
                },
                "labels": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "maxItems": 20
                },
                "estimated_duration_seconds": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 86400
                },
                "duration_progression_seconds": {
                  "type": "array",
                  "minItems": 1,
                  "maxItems": 52,
                  "items": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 86400
                  },
                  "description": "Ordered reference duration targets, typically one per week. Does not create dates, Programs or schedule entries.",
                  "deprecated": true
                }
              },
              "required": [
                "key",
                "blocks"
              ]
            },
            "minItems": 1,
            "maxItems": 50
          }
        }
      }
    }
  }
}