{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Sorta Modular Custom URL response",
  "type": "object",
  "required": [
    "v"
  ],
  "oneOf": [
    {
      "required": [
        "widget"
      ]
    },
    {
      "required": [
        "timeline"
      ]
    }
  ],
  "properties": {
    "v": {
      "const": 1,
      "description": "Protocol version."
    },
    "refresh": {
      "type": "number",
      "minimum": 300,
      "maximum": 86400,
      "default": 1800,
      "description": "Seconds until the next fetch."
    },
    "widget": {
      "$ref": "#/$defs/widget",
      "description": "What to show now. Shorthand for a one-entry timeline active immediately."
    },
    "timeline": {
      "type": "array",
      "minItems": 1,
      "maxItems": 24,
      "description": "Dated widgets; 'at' ascending, entries >= 60 s apart. The latest entry with at <= now is shown.",
      "items": {
        "type": "object",
        "required": [
          "at",
          "widget"
        ],
        "properties": {
          "at": {
            "type": "number",
            "description": "Epoch seconds this entry becomes active."
          },
          "widget": {
            "$ref": "#/$defs/widget"
          }
        }
      }
    }
  },
  "$defs": {
    "widget": {
      "anyOf": [
        {
          "$ref": "#/$defs/circleWidget"
        },
        {
          "$ref": "#/$defs/centerWidget"
        },
        {
          "$ref": "#/$defs/bezelWidget"
        }
      ],
      "description": "Must match the geometry of the requesting slot."
    },
    "color": {
      "type": "string",
      "pattern": "^#[0-9a-fA-F]{6}$",
      "description": "Quantized to the watch's 64-color palette; default white."
    },
    "circleWidget": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "type",
            "value"
          ],
          "properties": {
            "type": {
              "const": "text"
            },
            "value": {
              "type": "string",
              "maxLength": 8
            },
            "label": {
              "type": "string",
              "maxLength": 10
            },
            "color": {
              "$ref": "#/$defs/color"
            }
          }
        },
        {
          "type": "object",
          "required": [
            "type",
            "percent"
          ],
          "properties": {
            "type": {
              "const": "gauge"
            },
            "percent": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "value": {
              "type": "string",
              "maxLength": 8
            },
            "label": {
              "type": "string",
              "maxLength": 10
            },
            "color": {
              "$ref": "#/$defs/color"
            },
            "colors": {
              "type": "array",
              "minItems": 1,
              "maxItems": 8,
              "description": "Scale segments; 'to' values must not decrease.",
              "items": {
                "type": "object",
                "required": [
                  "to",
                  "color"
                ],
                "properties": {
                  "to": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 100
                  },
                  "color": {
                    "$ref": "#/$defs/color"
                  }
                }
              }
            }
          }
        }
      ]
    },
    "centerWidget": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "type",
            "line1"
          ],
          "properties": {
            "type": {
              "const": "lines"
            },
            "line1": {
              "type": "string",
              "maxLength": 14
            },
            "line2": {
              "type": "string",
              "maxLength": 18
            },
            "info": {
              "type": "string",
              "maxLength": 30
            },
            "color": {
              "$ref": "#/$defs/color"
            }
          }
        },
        {
          "type": "object",
          "required": [
            "type",
            "text"
          ],
          "properties": {
            "type": {
              "const": "textarea"
            },
            "text": {
              "type": "string",
              "maxLength": 79,
              "description": "Fills the whole block; newlines start new lines. No info field."
            },
            "color": {
              "$ref": "#/$defs/color"
            }
          }
        },
        {
          "type": "object",
          "required": [
            "type",
            "columns"
          ],
          "properties": {
            "type": {
              "const": "columns"
            },
            "columns": {
              "type": "array",
              "minItems": 2,
              "maxItems": 5,
              "items": {
                "type": "object",
                "required": [
                  "label",
                  "value"
                ],
                "properties": {
                  "label": {
                    "type": "string",
                    "maxLength": 6
                  },
                  "value": {
                    "type": "string",
                    "maxLength": 8
                  }
                }
              }
            },
            "info": {
              "type": "string",
              "maxLength": 30
            },
            "color": {
              "$ref": "#/$defs/color"
            }
          }
        }
      ]
    },
    "bezelWidget": {
      "type": "object",
      "required": [
        "type",
        "percent"
      ],
      "properties": {
        "type": {
          "const": "gauge"
        },
        "percent": {
          "type": "number",
          "minimum": 0,
          "maximum": 100
        },
        "color": {
          "$ref": "#/$defs/color"
        }
      }
    }
  }
}
