{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://redbook.fun/specification/1.0/schemas/type.schema.json",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "minLength": 1
    },
    "key": {
      "type": "string",
      "minLength": 1
    },
    "primitive": {
      "enum": [
        "element",
        "relationship"
      ]
    },
    "level": {
      "enum": [
        "type",
        "specialization"
      ]
    },
    "area": {
      "type": "string"
    },
    "parent": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "label": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "openSlots": {
      "type": "boolean"
    },
    "fields": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "kind": {
            "enum": [
              "any",
              "string",
              "boolean",
              "number",
              "integer",
              "decimal",
              "reference",
              "array",
              "object"
            ]
          },
          "description": {
            "type": "string"
          },
          "required": {
            "type": "boolean"
          },
          "default": {
            "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
          },
          "choices": {
            "type": "array",
            "items": {
              "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
            }
          }
        },
        "required": [
          "kind",
          "description",
          "required"
        ],
        "additionalProperties": false
      }
    },
    "slots": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "min": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "max": {
            "oneOf": [
              {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              {
                "type": "null"
              }
            ]
          },
          "allowedTypes": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "uniqueItems": true
          },
          "ordered": {
            "type": "boolean"
          },
          "unique": {
            "type": "boolean"
          }
        },
        "required": [
          "min",
          "max",
          "allowedTypes",
          "ordered",
          "unique"
        ],
        "additionalProperties": false
      }
    },
    "traits": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    }
  },
  "required": [
    "id",
    "key",
    "primitive",
    "level",
    "area",
    "parent",
    "label",
    "description",
    "openSlots",
    "fields",
    "slots",
    "traits"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "level": {
            "const": "type"
          }
        }
      },
      "then": {
        "properties": {
          "parent": {
            "type": "null"
          }
        }
      },
      "else": {
        "properties": {
          "parent": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "primitive": {
            "const": "element"
          }
        }
      },
      "then": {
        "properties": {
          "slots": {
            "maxProperties": 0
          }
        }
      }
    }
  ]
}
