{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "meta": {
      "type": "object",
      "properties": {
        "created_at": {
          "type": "string",
          "format": "date-time",
          "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])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time",
          "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])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
        },
        "deleted_at": {
          "type": "string",
          "format": "date-time",
          "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])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
        },
        "legacy_ref": {
          "type": "object",
          "properties": {
            "table": {
              "type": "string"
            },
            "key": {
              "type": ["string", "number"]
            },
            "row": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          },
          "required": ["table", "key", "row"]
        },
        "dataset": {
          "type": "string"
        }
      }
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^x-[a-z0-9]+-[a-z0-9-]+$"
      },
      "additionalProperties": {
        "$ref": "#/$defs/__schema0"
      }
    },
    "operation": {
      "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"]
    },
    "active": {
      "type": "boolean"
    },
    "scope": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "template_slot"
            },
            "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"]
            },
            "slot": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
            },
            "prescription": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
            },
            "body_sha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          "required": ["type", "version", "slot", "body_sha256"]
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "occurrence"
            },
            "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"]
            },
            "occurrence": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
            },
            "expected_revision": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            }
          },
          "required": ["type", "session", "occurrence"]
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "set"
            },
            "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"]
            },
            "occurrence": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
            },
            "set": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
            }
          },
          "required": ["type", "session", "occurrence", "set"]
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "chart_selector"
            },
            "chart": {
              "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"]
            },
            "selector_path": {
              "type": "string"
            },
            "expected_revision": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "definition_sha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          "required": ["type", "chart", "selector_path", "expected_revision", "definition_sha256"]
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "pattern": "^(?!(?:template_slot|occurrence|set|chart_selector)$)[\\s\\S]*$"
            }
          },
          "required": ["type"]
        }
      ]
    },
    "source_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"]
    },
    "target_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"]
    },
    "variant": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "ref": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
            },
            "catalog_key": {
              "type": "string"
            },
            "label": {
              "type": "string"
            },
            "attributes": {
              "type": "object",
              "properties": {
                "grip": {
                  "type": "string"
                },
                "hand_position": {
                  "type": "string"
                },
                "attachment": {
                  "type": "string"
                },
                "stance": {
                  "type": "string"
                },
                "equipment": {
                  "type": "string",
                  "known": ["band", "dumbbell", "barbell", "cable", "machine", "kettlebell", "bodyweight", "other"]
                },
                "support": {
                  "type": "string",
                  "known": ["back", "chest", "none"]
                },
                "body_position": {
                  "type": "string",
                  "known": ["seated", "standing", "kneeling"]
                },
                "laterality": {
                  "type": "string",
                  "known": ["bilateral", "unilateral", "alternating"]
                }
              }
            }
          },
          "required": ["label", "attributes"]
        },
        {
          "type": "string",
          "known": ["none"]
        }
      ]
    },
    "attribution": {
      "type": "string",
      "known": ["explicit_mapping", "historical_default"]
    }
  },
  "required": ["active", "scope", "source_exercise", "target_exercise", "attribution"],
  "$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/exercise_override@1.read.schema.json",
  "title": "Pigeon Open Data: exercise_override@1.read",
  "$comment": "Apache-2.0. Structural schema; use Zod/parseRecord for semantic invariants. This published schema URL is immutable.",
  "examples": [
    {
      "operation": {
        "record": "0194ab00-0000-7000-8000-000000000001"
      },
      "active": false,
      "scope": {
        "type": "template_slot",
        "version": {
          "record": "0194ab00-0000-7000-8000-000000000001"
        },
        "slot": "demo",
        "body_sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
      },
      "source_exercise": {
        "record": "0194ab00-0000-7000-8000-000000000001"
      },
      "target_exercise": {
        "record": "0194ab00-0000-7000-8000-000000000001"
      },
      "variant": {
        "label": "demo",
        "attributes": {}
      },
      "attribution": "explicit_mapping"
    }
  ]
}
