{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://redbook.fun/specification/1.0/schemas/templates.schema.json",
  "type": "object",
  "properties": {
    "formatVersion": {
      "const": "1.0"
    },
    "templates": {
      "type": "object",
      "minProperties": 1,
      "propertyNames": {
        "type": "string",
        "minLength": 1
      },
      "additionalProperties": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/templates.schema.json#/$defs/node"
      }
    },
    "selection": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "view": {
            "type": "string",
            "minLength": 1
          },
          "type": {
            "type": "string",
            "minLength": 1
          },
          "template": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "view",
          "template"
        ],
        "additionalProperties": false
      }
    },
    "defaultTemplate": {
      "type": "string",
      "minLength": 1
    }
  },
  "required": [
    "formatVersion",
    "templates",
    "selection"
  ],
  "additionalProperties": false,
  "$defs": {
    "node": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "text"
            },
            "text": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "text"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "value"
            },
            "path": {
              "type": "array",
              "items": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                ]
              },
              "minItems": 1
            },
            "fallback": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "path"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "element"
            },
            "tag": {
              "enum": [
                "div",
                "span",
                "section",
                "article",
                "header",
                "footer",
                "nav",
                "aside",
                "main",
                "p",
                "h1",
                "h2",
                "h3",
                "h4",
                "ul",
                "ol",
                "li",
                "dl",
                "dt",
                "dd",
                "strong",
                "em",
                "small",
                "time",
                "pre",
                "code",
                "blockquote",
                "table",
                "thead",
                "tbody",
                "tr",
                "th",
                "td",
                "hr",
                "br"
              ]
            },
            "attributes": {
              "type": "object",
              "patternProperties": {
                "^(?:id|class|title|role|aria-[a-z-]+|data-rb-[a-z-]+)$": {
                  "type": "string"
                }
              },
              "additionalProperties": false
            },
            "children": {
              "type": "array",
              "items": {
                "$ref": "https://redbook.fun/specification/1.0/schemas/templates.schema.json#/$defs/node"
              }
            }
          },
          "required": [
            "kind",
            "tag",
            "children"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "each"
            },
            "path": {
              "type": "array",
              "items": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                ]
              },
              "minItems": 1
            },
            "children": {
              "type": "array",
              "items": {
                "$ref": "https://redbook.fun/specification/1.0/schemas/templates.schema.json#/$defs/node"
              }
            },
            "empty": {
              "type": "array",
              "items": {
                "$ref": "https://redbook.fun/specification/1.0/schemas/templates.schema.json#/$defs/node"
              }
            }
          },
          "required": [
            "kind",
            "path",
            "children"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "slot"
            },
            "name": {
              "type": "string",
              "minLength": 1
            },
            "fallback": {
              "type": "array",
              "items": {
                "$ref": "https://redbook.fun/specification/1.0/schemas/templates.schema.json#/$defs/node"
              }
            }
          },
          "required": [
            "kind",
            "name"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "resource"
            },
            "path": {
              "type": "string",
              "minLength": 1
            },
            "alt": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "path",
            "alt"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "link"
            },
            "href": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "const": "literal"
                    },
                    "value": {
                      "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
                    }
                  },
                  "required": [
                    "kind",
                    "value"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "const": "path"
                    },
                    "path": {
                      "type": "array",
                      "items": {
                        "oneOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          }
                        ]
                      },
                      "minItems": 1
                    }
                  },
                  "required": [
                    "kind",
                    "path"
                  ],
                  "additionalProperties": false
                }
              ]
            },
            "children": {
              "type": "array",
              "items": {
                "$ref": "https://redbook.fun/specification/1.0/schemas/templates.schema.json#/$defs/node"
              }
            }
          },
          "required": [
            "kind",
            "href",
            "children"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "action"
            },
            "action": {
              "type": "string",
              "minLength": 1
            },
            "input": {
              "type": "object",
              "additionalProperties": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "const": "literal"
                      },
                      "value": {
                        "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
                      }
                    },
                    "required": [
                      "kind",
                      "value"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "const": "path"
                      },
                      "path": {
                        "type": "array",
                        "items": {
                          "oneOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            }
                          ]
                        },
                        "minItems": 1
                      }
                    },
                    "required": [
                      "kind",
                      "path"
                    ],
                    "additionalProperties": false
                  }
                ]
              }
            },
            "label": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "action",
            "input",
            "label"
          ],
          "additionalProperties": false
        }
      ]
    },
    "binding": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "literal"
            },
            "value": {
              "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
            }
          },
          "required": [
            "kind",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "path"
            },
            "path": {
              "type": "array",
              "items": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                ]
              },
              "minItems": 1
            }
          },
          "required": [
            "kind",
            "path"
          ],
          "additionalProperties": false
        }
      ]
    }
  }
}
