{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://redbook.fun/specification/1.0/schemas/template-context.schema.json",
  "type": "object",
  "properties": {
    "world": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "title": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "title",
        "description"
      ],
      "additionalProperties": false
    },
    "view": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "configuration": {
          "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json#/$defs/map"
        }
      },
      "required": [
        "id",
        "name",
        "configuration"
      ],
      "additionalProperties": false
    },
    "actor": {
      "type": "object",
      "properties": {
        "role": {
          "enum": [
            "reader-admin",
            "redbook-admin",
            "digital"
          ]
        },
        "digitalId": {
          "oneOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "role",
        "digitalId"
      ],
      "additionalProperties": false
    },
    "record": {
      "oneOf": [
        {
          "$ref": "https://redbook.fun/specification/1.0/schemas/record.schema.json"
        },
        {
          "type": "null"
        }
      ]
    },
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "type": {
            "type": "string",
            "minLength": 1
          },
          "primitive": {
            "enum": [
              "element",
              "relationship"
            ]
          },
          "title": {
            "type": "string"
          },
          "properties": {
            "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json#/$defs/map"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "uniqueItems": true
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "uniqueItems": true
          },
          "slots": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "attribution": {
            "type": "object",
            "properties": {
              "digitalId": {
                "type": "string",
                "minLength": 1
              },
              "credit": {
                "type": "object",
                "properties": {
                  "documentId": {
                    "type": "string",
                    "minLength": 1
                  },
                  "digitalId": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "documentId",
                  "digitalId",
                  "name"
                ],
                "additionalProperties": false
              }
            },
            "required": [],
            "additionalProperties": false,
            "anyOf": [
              {
                "required": [
                  "digitalId"
                ]
              },
              {
                "required": [
                  "credit"
                ]
              }
            ]
          },
          "recordedAt": {
            "type": "string",
            "pattern": "^[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\\.[0-9]{3}Z(?![\\s\\S])"
          },
          "sequence": {
            "type": "string",
            "pattern": "^[1-9][0-9]*(?![\\s\\S])"
          },
          "worldTime": {
            "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
          },
          "placement": {
            "oneOf": [
              {
                "$ref": "https://redbook.fun/specification/1.0/schemas/record.schema.json"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "type",
          "primitive",
          "title",
          "properties",
          "categories",
          "tags",
          "slots",
          "placement"
        ],
        "additionalProperties": false,
        "allOf": [
          {
            "if": {
              "properties": {
                "primitive": {
                  "const": "element"
                }
              }
            },
            "then": {
              "properties": {
                "slots": {
                  "maxProperties": 0
                }
              }
            },
            "else": {
              "properties": {
                "slots": {
                  "minProperties": 1
                }
              }
            }
          }
        ]
      }
    },
    "theme": {
      "type": "object",
      "properties": {
        "configuration": {
          "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json#/$defs/map"
        }
      },
      "required": [
        "configuration"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "world",
    "view",
    "actor",
    "record",
    "items",
    "theme"
  ],
  "additionalProperties": false
}
