{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://redbook.fun/specification/1.0/schemas/blueprint.schema.json",
  "type": "object",
  "properties": {
    "kind": {
      "const": "blueprint"
    },
    "formatVersion": {
      "const": "1.0"
    },
    "roots": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "records": {
      "type": "array",
      "items": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/record.schema.json"
      }
    },
    "types": {
      "type": "array",
      "items": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/type.schema.json"
      }
    },
    "categories": {
      "type": "array",
      "items": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/taxonomy.schema.json#/$defs/category"
      }
    },
    "tags": {
      "type": "array",
      "items": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/taxonomy.schema.json#/$defs/tag"
      }
    },
    "bindingRequirements": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "minLength": 1
          },
          "label": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "key",
          "label",
          "type"
        ],
        "additionalProperties": false
      }
    },
    "assets": {
      "type": "array",
      "items": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/asset.schema.json"
      }
    },
    "requiredParts": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "pattern": "^(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*\\.(?:/|$))[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)*(?![\\s\\S])"
      },
      "uniqueItems": true
    },
    "note": {
      "type": "string"
    },
    "resourceReferences": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "recordId": {
            "type": "string",
            "minLength": 1
          },
          "propertyPath": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "path": {
            "type": "string",
            "minLength": 1,
            "pattern": "^(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*\\.(?:/|$))[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)*(?![\\s\\S])"
          }
        },
        "required": [
          "recordId",
          "propertyPath",
          "path"
        ],
        "additionalProperties": false
      }
    },
    "exports": {
      "type": "object",
      "properties": {
        "records": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "types": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "categories": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      },
      "required": [
        "records",
        "types",
        "categories",
        "tags"
      ],
      "additionalProperties": false
    },
    "resourceDependencies": {
      "type": "object",
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "string",
          "minLength": 1,
          "pattern": "^(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*\\.(?:/|$))[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)*(?![\\s\\S])"
        },
        "uniqueItems": true
      }
    },
    "typeResources": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "typeId": {
            "type": "string",
            "minLength": 1
          },
          "parts": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "pattern": "^(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*\\.(?:/|$))[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)*(?![\\s\\S])"
            },
            "uniqueItems": true
          }
        },
        "required": [
          "typeId",
          "parts"
        ],
        "additionalProperties": false
      }
    },
    "components": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "minLength": 1
          },
          "packagePart": {
            "type": "string",
            "minLength": 1,
            "pattern": "^(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*\\.(?:/|$))[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)*(?![\\s\\S])"
          },
          "target": {
            "enum": [
              "redbook",
              "viewbox"
            ]
          },
          "targetId": {
            "type": "string",
            "minLength": 1
          },
          "configuration": {
            "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json#/$defs/map"
          }
        },
        "required": [
          "key",
          "packagePart",
          "target",
          "configuration"
        ],
        "additionalProperties": false,
        "allOf": [
          {
            "if": {
              "properties": {
                "target": {
                  "const": "viewbox"
                }
              }
            },
            "then": {
              "required": [
                "targetId"
              ]
            },
            "else": {
              "not": {
                "required": [
                  "targetId"
                ]
              }
            }
          }
        ]
      }
    }
  },
  "required": [
    "kind",
    "formatVersion",
    "roots",
    "records",
    "types",
    "categories",
    "tags",
    "bindingRequirements",
    "assets",
    "requiredParts",
    "exports"
  ],
  "additionalProperties": false,
  "description": "A reusable record graph, definition/taxonomy collection, bundled functionality, or a combination. Explicit exports distinguish reusable roots from carried dependencies.",
  "anyOf": [
    {
      "properties": {
        "exports": {
          "anyOf": [
            {
              "properties": {
                "records": {
                  "minItems": 1
                }
              }
            },
            {
              "properties": {
                "types": {
                  "minItems": 1
                }
              }
            },
            {
              "properties": {
                "categories": {
                  "minItems": 1
                }
              }
            },
            {
              "properties": {
                "tags": {
                  "minItems": 1
                }
              }
            }
          ]
        }
      }
    },
    {
      "required": [
        "components"
      ],
      "properties": {
        "components": {
          "minItems": 1
        }
      }
    }
  ]
}
