{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "meta": {
      "type": "object",
      "properties": {
        "created_at": {
          "type": ["string", "null"]
        },
        "updated_at": {
          "type": ["string", "null"]
        },
        "deleted_at": {
          "type": ["string", "null"]
        },
        "legacy_ref": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "table": {
                  "type": "string"
                },
                "key": {
                  "type": ["string", "number"]
                },
                "row": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                }
              },
              "required": ["table", "key", "row"],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        },
        "dataset": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^x-[a-z0-9]+-[a-z0-9-]+$"
      },
      "additionalProperties": {
        "$ref": "#/$defs/__schema0"
      }
    },
    "title": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "goal": {
      "type": "string"
    },
    "goal_text": {
      "type": "string"
    },
    "kind_hint": {
      "type": "string",
      "enum": ["schedule", "program"]
    },
    "advance": {
      "type": "string",
      "enum": ["calendar", "rolling"]
    },
    "finite": {
      "type": "boolean"
    },
    "progression_text": {
      "type": "string"
    },
    "starter": {
      "type": "object",
      "properties": {
        "key": {
          "type": "string"
        },
        "version": {
          "type": "string"
        }
      },
      "required": ["key", "version"],
      "additionalProperties": false
    },
    "equipment": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "target_muscles": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "contraindications": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "level": {
      "type": "string"
    },
    "raw": {
      "type": "string"
    },
    "schedule": {
      "type": "object",
      "properties": {
        "meta": {
          "type": "object",
          "properties": {
            "created_at": {
              "type": ["string", "null"]
            },
            "updated_at": {
              "type": ["string", "null"]
            },
            "deleted_at": {
              "type": ["string", "null"]
            },
            "legacy_ref": {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "table": {
                      "type": "string"
                    },
                    "key": {
                      "type": ["string", "number"]
                    },
                    "row": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    }
                  },
                  "required": ["table", "key", "row"],
                  "additionalProperties": false
                },
                {
                  "type": "null"
                }
              ]
            },
            "dataset": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "pattern": "^x-[a-z0-9]+-[a-z0-9-]+$"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema0"
          }
        },
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
        },
        "source_order": {
          "type": "number"
        },
        "mode": {
          "type": "string",
          "enum": ["repeat", "weekdays", "dated"]
        },
        "cycle_length_days": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "repeat_count": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "cycles": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "meta": {
                "type": "object",
                "properties": {
                  "created_at": {
                    "type": ["string", "null"]
                  },
                  "updated_at": {
                    "type": ["string", "null"]
                  },
                  "deleted_at": {
                    "type": ["string", "null"]
                  },
                  "legacy_ref": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "table": {
                            "type": "string"
                          },
                          "key": {
                            "type": ["string", "number"]
                          },
                          "row": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          }
                        },
                        "required": ["table", "key", "row"],
                        "additionalProperties": false
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "dataset": {
                    "type": "string"
                  }
                },
                "additionalProperties": false
              },
              "extensions": {
                "type": "object",
                "propertyNames": {
                  "type": "string",
                  "pattern": "^x-[a-z0-9]+-[a-z0-9-]+$"
                },
                "additionalProperties": {
                  "$ref": "#/$defs/__schema0"
                }
              },
              "id": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
              },
              "source_order": {
                "type": "number"
              },
              "index": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              "days": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "meta": {
                      "type": "object",
                      "properties": {
                        "created_at": {
                          "type": ["string", "null"]
                        },
                        "updated_at": {
                          "type": ["string", "null"]
                        },
                        "deleted_at": {
                          "type": ["string", "null"]
                        },
                        "legacy_ref": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "table": {
                                  "type": "string"
                                },
                                "key": {
                                  "type": ["string", "number"]
                                },
                                "row": {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                }
                              },
                              "required": ["table", "key", "row"],
                              "additionalProperties": false
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "dataset": {
                          "type": "string"
                        }
                      },
                      "additionalProperties": false
                    },
                    "extensions": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string",
                        "pattern": "^x-[a-z0-9]+-[a-z0-9-]+$"
                      },
                      "additionalProperties": {
                        "$ref": "#/$defs/__schema0"
                      }
                    },
                    "id": {
                      "type": "string",
                      "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
                    },
                    "source_order": {
                      "type": "number"
                    },
                    "day_index": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "local_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])))$"
                    },
                    "label": {
                      "type": "string"
                    },
                    "rest_day": {
                      "type": "boolean"
                    },
                    "phase": {
                      "type": "string",
                      "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
                    },
                    "sessions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "workout": {
                            "type": "object",
                            "properties": {
                              "record": {
                                "type": "string",
                                "format": "uuid",
                                "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                              }
                            },
                            "required": ["record"],
                            "additionalProperties": false
                          },
                          "version": {
                            "type": "object",
                            "properties": {
                              "record": {
                                "type": "string",
                                "format": "uuid",
                                "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                              }
                            },
                            "required": ["record"],
                            "additionalProperties": false
                          }
                        },
                        "required": ["workout"],
                        "additionalProperties": false
                      },
                      "atomic": true
                    }
                  },
                  "required": ["id", "day_index", "rest_day", "sessions"],
                  "additionalProperties": false
                }
              }
            },
            "required": ["id", "index", "days"],
            "additionalProperties": false
          }
        }
      },
      "required": ["id", "mode", "cycle_length_days", "cycles"],
      "additionalProperties": false
    },
    "phases": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "meta": {
            "type": "object",
            "properties": {
              "created_at": {
                "type": ["string", "null"]
              },
              "updated_at": {
                "type": ["string", "null"]
              },
              "deleted_at": {
                "type": ["string", "null"]
              },
              "legacy_ref": {
                "anyOf": [
                  {
                    "type": "object",
                    "properties": {
                      "table": {
                        "type": "string"
                      },
                      "key": {
                        "type": ["string", "number"]
                      },
                      "row": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 9007199254740991
                      }
                    },
                    "required": ["table", "key", "row"],
                    "additionalProperties": false
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "dataset": {
                "type": "string"
              }
            },
            "additionalProperties": false
          },
          "extensions": {
            "type": "object",
            "propertyNames": {
              "type": "string",
              "pattern": "^x-[a-z0-9]+-[a-z0-9-]+$"
            },
            "additionalProperties": {
              "$ref": "#/$defs/__schema0"
            }
          },
          "id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
          },
          "source_order": {
            "type": "number"
          },
          "title": {
            "type": "string"
          },
          "focus": {
            "type": "string"
          },
          "week_count": {
            "type": "integer",
            "minimum": 1,
            "maximum": 52
          },
          "week_targets": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "deload": {
                  "type": "boolean"
                },
                "load_factor": {
                  "type": "string",
                  "pattern": "^(?:0|[1-9]\\d*)(?:\\.\\d+)?$"
                },
                "set_delta": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "sets": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "rir_offset": {
                  "type": "number"
                },
                "compound_rir": {
                  "type": "number"
                },
                "isolation_rir": {
                  "type": "number"
                }
              },
              "required": ["deload"],
              "additionalProperties": false
            },
            "atomic": true
          }
        },
        "required": ["id", "title", "week_targets"],
        "additionalProperties": false
      }
    },
    "progression_rules": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "meta": {
            "type": "object",
            "properties": {
              "created_at": {
                "type": ["string", "null"]
              },
              "updated_at": {
                "type": ["string", "null"]
              },
              "deleted_at": {
                "type": ["string", "null"]
              },
              "legacy_ref": {
                "anyOf": [
                  {
                    "type": "object",
                    "properties": {
                      "table": {
                        "type": "string"
                      },
                      "key": {
                        "type": ["string", "number"]
                      },
                      "row": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 9007199254740991
                      }
                    },
                    "required": ["table", "key", "row"],
                    "additionalProperties": false
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "dataset": {
                "type": "string"
              }
            },
            "additionalProperties": false
          },
          "extensions": {
            "type": "object",
            "propertyNames": {
              "type": "string",
              "pattern": "^x-[a-z0-9]+-[a-z0-9-]+$"
            },
            "additionalProperties": {
              "$ref": "#/$defs/__schema0"
            }
          },
          "id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
          },
          "source_order": {
            "type": "number"
          },
          "applies_to": {
            "type": "object",
            "properties": {
              "workout": {
                "type": "object",
                "properties": {
                  "record": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  }
                },
                "required": ["record"],
                "additionalProperties": false
              },
              "slot": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
              }
            },
            "required": ["workout", "slot"],
            "additionalProperties": false
          },
          "exercise": {
            "type": "object",
            "properties": {
              "record": {
                "type": "string",
                "format": "uuid",
                "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
              }
            },
            "required": ["record"],
            "additionalProperties": false
          },
          "model": {
            "type": "string",
            "minLength": 1
          },
          "params": {
            "$ref": "#/$defs/__schema0"
          }
        },
        "required": ["id", "applies_to", "model", "params"],
        "additionalProperties": false
      }
    }
  },
  "required": ["title", "equipment", "target_muscles", "contraindications", "phases", "progression_rules"],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema0"
          }
        }
      ]
    }
  },
  "$id": "https://sendtopigeon.com/schemas/program@1.schema.json",
  "title": "Pigeon Open Data: program@1",
  "$comment": "Apache-2.0. Structural schema; use Zod/parseRecord for semantic invariants. This published schema URL is immutable.",
  "examples": [
    {
      "title": "demo",
      "equipment": [],
      "target_muscles": [],
      "contraindications": [],
      "phases": [],
      "progression_rules": []
    }
  ]
}
