{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kabinethq.com/protocol/1/page.schema.json",
  "title": "Page",
  "description": "Pages as trees of blocks: custom pages and a resource's own screens.",
  "$defs": {
    "PageSchema": {
      "title": "PageSchema",
      "description": "`GET /panel/pages/{page}/schema`.",
      "type": "object",
      "required": [
        "version",
        "page",
        "label",
        "layout"
      ],
      "properties": {
        "version": {
          "const": 1
        },
        "page": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string"
        },
        "layout": {
          "$ref": "#/$defs/Layout"
        }
      },
      "additionalProperties": false
    },
    "Layout": {
      "title": "Layout",
      "description": "A tree of blocks; the server has dropped what this user may not see, and the containers left empty.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/Block"
      }
    },
    "Block": {
      "title": "Block",
      "type": "object",
      "required": [
        "type"
      ],
      "discriminator": {
        "propertyName": "type"
      },
      "oneOf": [
        {
          "$ref": "#/$defs/SectionBlock"
        },
        {
          "$ref": "#/$defs/GridBlock"
        },
        {
          "$ref": "#/$defs/TabsBlock"
        },
        {
          "$ref": "#/$defs/TableBlock"
        },
        {
          "$ref": "#/$defs/FormBlock"
        },
        {
          "$ref": "#/$defs/InfolistBlock"
        },
        {
          "$ref": "#/$defs/ActionsBlock"
        },
        {
          "$ref": "#/$defs/MetricBlock"
        }
      ]
    },
    "SectionBlock": {
      "title": "SectionBlock",
      "description": "Panels one after another.",
      "type": "object",
      "required": [
        "type",
        "children"
      ],
      "properties": {
        "type": {
          "const": "section"
        },
        "label": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "children": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/Block"
          }
        }
      },
      "additionalProperties": false
    },
    "GridBlock": {
      "title": "GridBlock",
      "type": "object",
      "required": [
        "type",
        "columns",
        "children"
      ],
      "properties": {
        "type": {
          "const": "grid"
        },
        "columns": {
          "type": "integer",
          "minimum": 1
        },
        "children": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/Block"
          }
        }
      },
      "additionalProperties": false
    },
    "TabsBlock": {
      "title": "TabsBlock",
      "type": "object",
      "required": [
        "type",
        "tabs"
      ],
      "properties": {
        "type": {
          "const": "tabs"
        },
        "tabs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "label",
              "children"
            ],
            "properties": {
              "label": {
                "type": "string"
              },
              "children": {
                "type": "array",
                "minItems": 1,
                "items": {
                  "$ref": "#/$defs/Block"
                }
              }
            },
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    },
    "TableBlock": {
      "title": "TableBlock",
      "description": "A resource's list. `id`: the block's name, for a detail's `master` (a named table's rows select instead of opening). `master`: the key of the row selected in table `block` goes into `filter[filter]`. `filters`: fixed `filter[...]` values, never shown. `actions`: the actions it offers (all of the resource's when absent). `record_filter`: a relation manager's filter, which gets the page record's key.",
      "type": "object",
      "required": [
        "type",
        "resource"
      ],
      "properties": {
        "type": {
          "const": "table"
        },
        "resource": {
          "type": "string",
          "minLength": 1
        },
        "id": {
          "type": "string",
          "minLength": 1
        },
        "master": {
          "type": "object",
          "required": [
            "block",
            "filter"
          ],
          "properties": {
            "block": {
              "type": "string",
              "minLength": 1
            },
            "filter": {
              "type": "string",
              "minLength": 1
            }
          },
          "additionalProperties": false
        },
        "filters": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": true
        },
        "actions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "record_filter": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false,
      "not": {
        "required": [
          "master",
          "record_filter"
        ]
      }
    },
    "FormBlock": {
      "title": "FormBlock",
      "description": "The record's form: only on a resource's create / edit page.",
      "type": "object",
      "required": [
        "type",
        "resource"
      ],
      "properties": {
        "type": {
          "const": "form"
        },
        "resource": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "InfolistBlock": {
      "title": "InfolistBlock",
      "description": "The record's entries: only on a resource's view page.",
      "type": "object",
      "required": [
        "type",
        "resource"
      ],
      "properties": {
        "type": {
          "const": "infolist"
        },
        "resource": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "ActionsBlock": {
      "title": "ActionsBlock",
      "description": "Record actions of the page's record; a block left with no names is dropped.",
      "type": "object",
      "required": [
        "type",
        "resource",
        "names"
      ],
      "properties": {
        "type": {
          "const": "actions"
        },
        "resource": {
          "type": "string",
          "minLength": 1
        },
        "names": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "additionalProperties": false
    },
    "MetricBlock": {
      "title": "MetricBlock",
      "description": "A card whose numbers come from `GET /panel/metrics/{name}`. The first range is the default; `refresh`: seconds between refetches.",
      "type": "object",
      "required": [
        "type",
        "name",
        "component",
        "label"
      ],
      "properties": {
        "type": {
          "const": "metric"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "component": {
          "enum": [
            "ValueMetric",
            "TrendMetric",
            "PartitionMetric",
            "ProgressMetric"
          ]
        },
        "label": {
          "type": "string"
        },
        "ranges": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "common.schema.json#/$defs/Choice"
          }
        },
        "refresh": {
          "type": "integer",
          "minimum": 1
        }
      },
      "additionalProperties": false
    }
  }
}
