{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://redbook.fun/specification/1.0/schemas/record.schema.json",
  "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"
    }
  },
  "required": [
    "id",
    "type",
    "primitive",
    "title",
    "properties",
    "categories",
    "tags",
    "slots"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "primitive": {
            "const": "element"
          }
        }
      },
      "then": {
        "properties": {
          "slots": {
            "maxProperties": 0
          }
        }
      },
      "else": {
        "properties": {
          "slots": {
            "minProperties": 1
          }
        }
      }
    }
  ]
}
