{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/distribution/latest-compatible-request.v1.schema.json",
  "title": "RootBlocks Latest Compatible Request v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "requestId",
    "requestedAt",
    "bundleId",
    "operation",
    "consumerProfile",
    "selectionPolicy"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.latest-compatible-request/v1"
    },
    "requestId": {
      "type": "string",
      "pattern": "^dist-request-[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "requestedAt": {
      "type": "string",
      "format": "date-time"
    },
    "bundleId": {
      "$ref": "#/$defs/id"
    },
    "operation": {
      "enum": ["generate", "validate", "compile", "run", "debug", "package", "sign", "release", "sync-components"]
    },
    "consumerProfile": {
      "$ref": "#/$defs/consumerProfile"
    },
    "currentBundle": {
      "$ref": "#/$defs/currentBundle"
    },
    "selectionPolicy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["includePrerelease", "allowDeprecated", "requireSigned", "criticalUpdatesOnly"],
      "properties": {
        "includePrerelease": {
          "type": "boolean"
        },
        "allowDeprecated": {
          "type": "boolean"
        },
        "requireSigned": {
          "type": "boolean",
          "const": true
        },
        "criticalUpdatesOnly": {
          "type": "boolean"
        }
      }
    }
  },
  "$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.-]+)?$"
    },
    "hash": {
      "type": "string",
      "pattern": "^[a-f0-9]{64,128}$"
    },
    "consumerProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "consumerName",
        "version",
        "supportedBundleMajors",
        "supportedSchemaFamilies",
        "capabilities",
        "enforcementMode"
      ],
      "properties": {
        "consumerName": {
          "enum": ["rootblocks-console", "darkfactory", "builderx", "rbstd", "agent", "custom"]
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "supportedBundleMajors": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "integer",
            "minimum": 0
          },
          "uniqueItems": true
        },
        "supportedSchemaFamilies": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "capabilities": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
          },
          "uniqueItems": true
        },
        "enforcementMode": {
          "enum": ["advisory", "enforced"]
        },
        "cacheState": {
          "enum": ["current", "stale-warning", "stale-critical", "invalid", "quarantined", "refreshing"]
        },
        "architectureProfileSupport": {
          "type": "object",
          "additionalProperties": false,
          "required": ["supportsArchitectureProfiles", "supportedProfiles"],
          "properties": {
            "supportsArchitectureProfiles": {
              "type": "boolean"
            },
            "supportedProfiles": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/supportedArchitectureProfile"
              }
            }
          }
        }
      }
    },
    "supportedArchitectureProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["profileId", "supportedMajors", "supportedLanguages", "supportedRuntimes", "rendererCapabilities"],
      "properties": {
        "profileId": {
          "$ref": "#/$defs/id"
        },
        "supportedMajors": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "integer",
            "minimum": 0
          },
          "uniqueItems": true
        },
        "supportedLanguages": {
          "type": "array",
          "items": {
            "enum": ["dotnet", "node", "python", "java", "go", "custom"]
          },
          "uniqueItems": true
        },
        "supportedRuntimes": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9.+-]{0,80}$"
          },
          "uniqueItems": true
        },
        "rendererCapabilities": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
          },
          "uniqueItems": true
        }
      }
    },
    "currentBundle": {
      "type": "object",
      "additionalProperties": false,
      "required": ["bundleId", "version", "manifestHash", "cacheState"],
      "properties": {
        "bundleId": {
          "$ref": "#/$defs/id"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "manifestHash": {
          "$ref": "#/$defs/hash"
        },
        "cacheState": {
          "enum": ["current", "stale-warning", "stale-critical", "invalid", "quarantined", "refreshing"]
        }
      }
    }
  }
}
