{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/cache/standard-cache-lock.v1.schema.json",
  "title": "RootBlocks Standard Cache Lock v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "lockId",
    "composedAt",
    "enforcementMode",
    "global",
    "extensions",
    "componentExposure",
    "buildPacks",
    "packageArtifacts",
    "compatibility",
    "stores",
    "composition"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.standard-cache-lock/v1"
    },
    "lockId": {
      "$ref": "#/$defs/id"
    },
    "composedAt": {
      "type": "string",
      "format": "date-time"
    },
    "enforcementMode": {
      "enum": ["advisory", "enforced"]
    },
    "global": {
      "$ref": "#/$defs/globalBundleRef"
    },
    "extensions": {
      "type": "object",
      "additionalProperties": false,
      "required": ["organization", "project", "personal"],
      "properties": {
        "organization": {
          "type": "array",
          "items": { "$ref": "#/$defs/extensionBundleRef" }
        },
        "project": {
          "type": "array",
          "items": { "$ref": "#/$defs/extensionBundleRef" }
        },
        "personal": {
          "type": "array",
          "items": { "$ref": "#/$defs/extensionBundleRef" }
        }
      }
    },
    "componentExposure": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/componentExposure"
      }
    },
    "buildPacks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/artifactRef"
      }
    },
    "packageArtifacts": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/artifactRef"
      }
    },
    "compatibility": {
      "type": "object",
      "additionalProperties": false,
      "required": ["result", "decisionPath"],
      "properties": {
        "result": {
          "enum": ["allow", "warn"]
        },
        "decisionPath": {
          "$ref": "#/$defs/path"
        }
      }
    },
    "stores": {
      "type": "object",
      "additionalProperties": false,
      "required": ["globalAssetStore", "externalComponentStores", "genericExternalAssetWrites", "componentsOnlyExtensions"],
      "properties": {
        "globalAssetStore": {
          "$ref": "#/$defs/path"
        },
        "externalComponentStores": {
          "type": "object",
          "additionalProperties": false,
          "required": ["organization", "project", "personal"],
          "properties": {
            "organization": { "$ref": "#/$defs/path" },
            "project": { "$ref": "#/$defs/path" },
            "personal": { "$ref": "#/$defs/path" }
          }
        },
        "genericExternalAssetWrites": {
          "const": "fail-closed"
        },
        "componentsOnlyExtensions": {
          "const": true
        }
      }
    },
    "composition": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state", "conflictOutcomes"],
      "properties": {
        "state": {
          "enum": ["ready", "degraded"]
        },
        "conflictOutcomes": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["severity", "message"],
            "properties": {
              "severity": {
                "enum": ["info", "warning"]
              },
              "message": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        }
      }
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "semver": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[A-Za-z0-9.-]+)?(\\+[A-Za-z0-9.-]+)?$"
    },
    "path": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_./@-]+$"
    },
    "hash": {
      "type": "string",
      "pattern": "^[a-f0-9]{64,128}$"
    },
    "globalBundleRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["bundleId", "bundleKind", "version", "manifestHash", "cacheMetadataPath"],
      "properties": {
        "bundleId": { "$ref": "#/$defs/id" },
        "bundleKind": { "const": "rootblocks-global-standard" },
        "version": { "$ref": "#/$defs/semver" },
        "manifestHash": { "$ref": "#/$defs/hash" },
        "cacheMetadataPath": { "$ref": "#/$defs/path" }
      }
    },
    "extensionBundleRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["bundleId", "bundleKind", "scope", "version", "manifestHash", "cacheMetadataPath", "assetKinds"],
      "properties": {
        "bundleId": { "$ref": "#/$defs/id" },
        "bundleKind": {
          "enum": [
            "organization-component-extension",
            "project-component-extension",
            "personal-component-extension"
          ]
        },
        "scope": {
          "enum": ["organization", "project", "personal"]
        },
        "version": { "$ref": "#/$defs/semver" },
        "manifestHash": { "$ref": "#/$defs/hash" },
        "cacheMetadataPath": { "$ref": "#/$defs/path" },
        "assetKinds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "const": "component"
          },
          "uniqueItems": true
        }
      }
    },
    "artifactRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "version", "hash", "path"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "version": { "$ref": "#/$defs/semver" },
        "hash": { "$ref": "#/$defs/hash" },
        "path": { "$ref": "#/$defs/path" }
      }
    },
    "componentExposure": {
      "type": "object",
      "additionalProperties": false,
      "required": ["componentId", "sourceExtensionBundleId", "buildPackId", "packageArtifactId"],
      "properties": {
        "componentId": { "$ref": "#/$defs/id" },
        "sourceExtensionBundleId": { "$ref": "#/$defs/id" },
        "buildPackId": { "$ref": "#/$defs/id" },
        "packageArtifactId": { "$ref": "#/$defs/id" }
      }
    }
  }
}
