{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kabinethq.com/protocol/1/metrics.schema.json",
  "title": "Metrics",
  "description": "`GET /panel/metrics/{name}`: which shape depends on the block's `component`, which the route doesn't know.",
  "$defs": {
    "MetricData": {
      "title": "MetricData",
      "oneOf": [
        { "$ref": "#/$defs/ValueData" },
        { "$ref": "#/$defs/ProgressData" },
        { "$ref": "#/$defs/PartitionData" },
        { "$ref": "#/$defs/TrendData" }
      ]
    },
    "ValueData": {
      "title": "ValueData",
      "description": "A ValueMetric; with ranges also `previous`, the period before of the same length.",
      "type": "object",
      "required": ["value"],
      "properties": {
        "value": { "type": "number" },
        "previous": { "type": "number" }
      },
      "additionalProperties": false
    },
    "ProgressData": {
      "title": "ProgressData",
      "type": "object",
      "required": ["value", "target"],
      "properties": {
        "value": { "type": "number" },
        "target": { "type": "number" }
      },
      "additionalProperties": false
    },
    "PartitionData": {
      "title": "PartitionData",
      "description": "One slice per option, in the options' order, empty ones too.",
      "type": "object",
      "required": ["slices"],
      "properties": {
        "slices": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["key", "label", "value"],
            "properties": {
              "key": { "type": "string" },
              "label": { "type": "string" },
              "value": { "type": "number" }
            },
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    },
    "TrendData": {
      "title": "TrendData",
      "description": "One point per day, oldest first, today last, empty days 0.",
      "type": "object",
      "required": ["points"],
      "properties": {
        "points": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["label", "value"],
            "properties": {
              "label": { "$ref": "common.schema.json#/$defs/Day" },
              "value": { "type": "number" }
            },
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    }
  }
}
