{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "allOf": [
    {
      "properties": {
        "version": {
          "type": "string",
          "pattern": "^1\\.[\\d]+\\.[\\d]+$"
        },
        "snippets": {
          "type": "array",
          "items": {
            "oneOf": [
              { "$ref": "#/definitions/SectionSnippet" },
              { "$ref": "#/definitions/ContentBlockSnippet" },
              { "$ref": "#/definitions/NestableSnippet" }
            ]
          }
        }
      },
      "required": [
        "version",
        "snippets"
      ]
    },
    {
      "oneOf": [
        {
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "Chapter"
              ]
            },
            "title": {
              "type": "string",
              "minLength": 1
            },
            "layout": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "palette": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "pattern": "^palette-[\\d]$"
                }
              }
            }
          },
          "required": [
            "type",
            "title"
          ]
        },
        {
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "BriefingContent"
              ]
            },
            "layout": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "palette": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "pattern": "^palette-[\\d]$"
                }
              }
            }
          },
          "required": [
            "type"
          ]
        }
      ]
    }
  ],
  "definitions": {
    "NestableSnippet": {
      "oneOf": [
        { "$ref": "#/definitions/TextSnippet" },
        { "$ref": "#/definitions/ListSnippet" },
        { "$ref": "#/definitions/TableSnippet" },
        { "$ref": "#/definitions/FigureSnippet" },
        { "$ref": "#/definitions/FigureWithTableSnippet" },
        { "$ref": "#/definitions/PictureSnippet" },
        { "$ref": "#/definitions/FullSizePictureSnippet" }
      ]
    },
    "SectionSnippet": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "Section"
          ]
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "definition": {
          "type": "object",
          "properties": {
            "level": {
              "type": "number",
              "minimum": 1,
              "maximum": 3
            }
          },
          "required": [
            "level"
          ]
        },
        "layout": {
          "$ref": "#/definitions/Layout"
        }
      },
      "required": [
        "type",
        "title",
        "definition"
      ]
    },
    "TextSnippet": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "Text"
          ]
        },
        "content": {
          "type": "string",
          "format": "HTML"
        },
        "definition": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "style": {
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "Glossary",
                "Quote",
                "Summary",
                null
              ]
            }
          }
        }
      },
      "required": [
        "type",
        "content"
      ]
    },
    "ListSnippet": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "List"
          ]
        },
        "snippets": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/TextSnippet"
          },
          "minItems": 1
        }
      },
      "required": [
        "type",
        "snippets"
      ]
    },
    "TableSnippet": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "Table"
          ]
        },
        "title": {
          "type": "string",
          "format": "HTML"
        },
        "content": {
          "type": "string",
          "format": "HTML"
        },
        "metadata": {
          "$ref": "#/definitions/ExhibitMetadata"
        }
      },
      "required": [
        "type",
        "title",
        "content",
        "metadata"
      ]
    },
    "FigureSnippet": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "Figure"
          ]
        },
        "title": {
          "type": "string",
          "format": "HTML"
        },
        "attachments": {
          "$ref": "#/definitions/ImageAttachment"
        },
        "metadata": {
          "$ref": "#/definitions/ExhibitMetadata"
        }
      },
      "required": [
        "type",
        "title",
        "attachments",
        "metadata"
      ]
    },
    "FigureWithTableSnippet": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "FigureWithTable"
          ]
        },
        "title": {
          "type": "string",
          "format": "HTML"
        },
        "content": {
          "type": "string",
          "format": "HTML"
        },
        "attachments": {
          "$ref": "#/definitions/ImageAttachment"
        },
        "metadata": {
          "$ref": "#/definitions/ExhibitMetadata"
        }
      },
      "required": [
        "type",
        "title",
        "content",
        "attachments",
        "metadata"
      ]
    },
    "PictureSnippet": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "Picture"
          ]
        },
        "attachments": {
          "$ref": "#/definitions/ImageAttachment"
        }
      },
      "required": [
        "type",
        "attachments"
      ]
    },
    "FullSizePictureSnippet": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "FullSizePicture"
          ]
        },
        "attachments": {
          "$ref": "#/definitions/ImageAttachment"
        }
      },
      "required": [
        "type",
        "attachments"
      ]
    },
    "ContentBlockSnippet": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "ContentBlock"
          ]
        },
        "definition": {
          "type": "object",
          "properties": {
            "blockType": {
              "type": "string",
              "enum": [
                "OneColumn",
                "TwoColumn",
                "TwoColumnOneThird",
                "TwoColumnTwoThird",
                "ThreeColumn"
              ]
            }
          },
          "required": [
            "blockType"
          ]
        },
        "snippets": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ContentBlockColumnSnippet"
          },
          "minItems": 1,
          "maxItems": 3
        },
        "layout": {
          "$ref": "#/definitions/Layout"
        }
      },
      "required": [
        "type",
        "definition",
        "snippets"
      ]
    },
    "ContentBlockColumnSnippet": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "ContentBlockColumn"
          ]
        },
        "snippets": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/NestableSnippet"
          },
          "minItems": 1
        }
      },
      "required": [
        "type",
        "snippets"
      ]
    },
    "ExhibitMetadata": {
      "type": "object",
      "properties": {
        "notes": {
          "type": [
            "string",
            "null"
          ],
          "format": "HTML"
        },
        "source": {
          "type": [
            "string",
            "null"
          ],
          "format": "HTML"
        },
        "keywords": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string"
          }
        }
      }
    },
    "ImageAttachment": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^~/blobs/.+(\\.jpg|\\.jpeg|\\.png|\\.gif)$"
      },
      "maxItems": 1,
      "minItems": 1
    },
    "Layout": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "background": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "image": {
              "type": [
                "string",
                "null"
              ],
              "pattern": "^~/blobs/.+(\\.jpg|\\.jpeg|\\.png|\\.gif)$"
            },
            "opacity": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 1
            }
          },
          "required": [
            "image",
            "opacity"
          ]
        },
        "palette": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^palette-[\\d]$"
        }
      }
    }
  }
}

