{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.baijimu.com/contracts/bundle-project-manifest/7.0.0/schema.json",
  "title": "Baijimu Bundle Project Manifest",
  "description": "Git-owned Bundle source document stored at the project-root path baijimu.bundle.json.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "definition"
  ],
  "properties": {
    "schemaVersion": {
      "const": "7.0.0"
    },
    "definition": {
      "$ref": "#/$defs/definition"
    }
  },
  "$defs": {
    "definition": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "lifecyclePlugins": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/pluginBinding"
          },
          "default": []
        },
        "resources": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/resourceSelection"
          },
          "default": []
        }
      }
    },
    "nonBlank": {
      "type": "string",
      "minLength": 1,
      "pattern": "\\S"
    },
    "exactSemanticVersion": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$"
    },
    "domainObject": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "resourceType",
        "resourceKey"
      ],
      "properties": {
        "type": {
          "const": "RESOURCE"
        },
        "resourceType": {
          "type": "string",
          "pattern": "^[A-Z][A-Z0-9_]{0,31}$"
        },
        "resourceKey": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[^/\\s]+$"
        }
      }
    },
    "propertyNames": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 191,
        "pattern": "^[^\\s/]+$"
      }
    },
    "pluginGrant": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "object",
        "readProperties",
        "writeProperties",
        "credentialProperties"
      ],
      "properties": {
        "object": {
          "$ref": "#/$defs/domainObject"
        },
        "readProperties": {
          "$ref": "#/$defs/propertyNames"
        },
        "writeProperties": {
          "$ref": "#/$defs/propertyNames"
        },
        "credentialProperties": {
          "$ref": "#/$defs/propertyNames"
        },
        "instanceRefProperty": {
          "type": "string",
          "minLength": 1,
          "maxLength": 191,
          "pattern": "^[^\\s/]+$"
        }
      }
    },
    "pluginBinding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "pluginId",
        "protocolVersion",
        "order",
        "failurePolicy",
        "configuration",
        "resources"
      ],
      "properties": {
        "pluginId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 191,
          "pattern": "^[^\\s/]+$"
        },
        "protocolVersion": {
          "$ref": "#/$defs/exactSemanticVersion"
        },
        "order": {
          "type": "integer",
          "minimum": -2147483648,
          "maximum": 2147483647
        },
        "failurePolicy": {
          "enum": [
            "FAIL_FAST",
            "WARN_CONTINUE"
          ]
        },
        "configuration": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "schemaVersion",
            "values"
          ],
          "properties": {
            "schemaVersion": {
              "$ref": "#/$defs/exactSemanticVersion"
            },
            "values": {
              "type": "object",
              "additionalProperties": true
            }
          }
        },
        "resources": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/pluginGrant"
          }
        }
      }
    },
    "resourceSelection": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "resourceType",
        "resourceKey",
        "semanticVersion"
      ],
      "properties": {
        "resourceType": {
          "type": "string",
          "pattern": "^[A-Z][A-Z0-9_]{0,31}$"
        },
        "resourceKey": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[^/\\s]+$"
        },
        "semanticVersion": {
          "$ref": "#/$defs/exactSemanticVersion"
        }
      }
    }
  }
}
