{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "@bedrock-core authored pack manifest",
  "description": "Native manifest v3 fields, inheritance and pack-owned addon metadata.",
  "type": "object",
  "if": {
    "not": {
      "required": [
        "extends"
      ]
    }
  },
  "then": {
    "required": [
      "format_version",
      "header",
      "modules"
    ]
  },
  "properties": {
    "$schema": {
      "type": "string"
    },
    "extends": {
      "type": "string",
      "pattern": "^\\.\\.?[/\\\\]"
    },
    "format_version": {
      "const": 3
    },
    "namespace": {
      "$ref": "#/definitions/namespace"
    },
    "thumbnail": {
      "type": "string",
      "minLength": 1,
      "description": "PNG path relative to the behavior pack or its selected resource pack."
    },
    "optionalDependencies": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "$ref": "#/definitions/dependency"
      },
      "description": "Optional dependencies use the same authored objects as required dependencies and add no native load requirement."
    },
    "header": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "uuid": {
          "$ref": "#/definitions/uuid"
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "min_engine_version": {
          "type": "string",
          "minLength": 1
        },
        "pack_scope": {
          "enum": [
            "world",
            "global",
            "any"
          ]
        }
      }
    },
    "metadata": {
      "type": "object",
      "properties": {
        "authors": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "license": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "generated_with": {
          "type": "object"
        }
      }
    },
    "modules": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "type",
          "uuid"
        ],
        "properties": {
          "type": {
            "enum": [
              "data",
              "resources",
              "script",
              "world_template",
              "skin_pack"
            ]
          },
          "uuid": {
            "$ref": "#/definitions/uuid"
          },
          "version": {
            "type": "string",
            "minLength": 1
          },
          "language": {
            "const": "javascript"
          },
          "entry": {
            "type": "string",
            "pattern": "^scripts/.+\\.(js|ts|tsx|mts|cts)$",
            "description": "Authored script path. Builder compiles TypeScript entries and exports the corresponding .js path."
          }
        }
      }
    },
    "dependencies": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/dependency"
      }
    }
  },
  "definitions": {
    "namespace": {
      "type": "string",
      "pattern": "^[a-z0-9_]+$",
      "not": {
        "const": "minecraft"
      }
    },
    "uuid": {
      "type": "string",
      "pattern": "^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$"
    },
    "dependency": {
      "type": "object",
      "not": {
        "anyOf": [
          {
            "required": [
              "pack"
            ]
          },
          {
            "required": [
              "module"
            ]
          }
        ]
      },
      "properties": {
        "uuid": {
          "$ref": "#/definitions/uuid"
        },
        "namespace": {
          "$ref": "#/definitions/namespace"
        },
        "module_name": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string",
          "minLength": 1
        }
      },
      "oneOf": [
        {
          "required": [
            "namespace"
          ],
          "not": {
            "anyOf": [
              {
                "required": [
                  "uuid"
                ]
              },
              {
                "required": [
                  "module_name"
                ]
              }
            ]
          }
        },
        {
          "required": [
            "uuid"
          ],
          "not": {
            "required": [
              "module_name"
            ]
          }
        },
        {
          "required": [
            "module_name"
          ],
          "not": {
            "required": [
              "uuid"
            ]
          },
          "if": {
            "properties": {
              "module_name": {
                "pattern": "^@minecraft/"
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "namespace"
              ]
            }
          }
        }
      ]
    }
  }
}
