{
  "$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"
      }
    },
    "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
    },
    "day": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
    },
    "occurrence_key": {
      "type": "string"
    },
    "planned_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])))$"
    },
    "scheduled_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])))$"
    },
    "time_of_day": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": ["planned", "skipped", "completed", "cancelled"]
    },
    "session": {
      "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
    },
    "link_source": {
      "type": "string"
    },
    "phase": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
    },
    "week_index": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "sequence_index": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "notes": {
      "type": "string"
    }
  },
  "required": ["workout", "planned_date", "scheduled_date", "status"],
  "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/planned_workout@1.schema.json",
  "title": "Pigeon Open Data: planned_workout@1",
  "$comment": "Apache-2.0. Structural schema; use Zod/parseRecord for semantic invariants. This published schema URL is immutable.",
  "examples": [
    {
      "workout": {
        "record": "0194ab00-0000-7000-8000-000000000001"
      },
      "planned_date": "2026-01-01",
      "scheduled_date": "2026-01-01",
      "status": "planned"
    }
  ]
}
