{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/welkaim/ea-codex/schemas/v1/variability-specification.json",
  "title": "VariabilitySpecification",
  "description": "Permitted variation envelope for a product, platform, or program family. Used in Chapter 5 to govern SAP S/4HANA country variants under clean-core constraints. Consumed at every transition gate as deterministic input.",
  "type": "object",
  "required": ["apiVersion", "kind", "metadata", "spec"],
  "properties": {
    "apiVersion": { "$ref": "_common.json#/$defs/apiVersion" },
    "kind": { "type": "string", "const": "VariabilitySpecification" },
    "metadata": { "$ref": "_common.json#/$defs/metadata" },
    "spec": {
      "type": "object",
      "required": ["scope", "variationPoints"],
      "properties": {
        "scope": {
          "type": "object",
          "required": ["family"],
          "properties": {
            "family": { "type": "string" },
            "appliesTo": {
              "type": "array",
              "items": { "type": "string" }
            }
          },
          "additionalProperties": true
        },
        "variationPoints": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["id", "classification", "bindingTime"],
            "properties": {
              "id": { "type": "string" },
              "classification": {
                "type": "string",
                "description": "Free text classification within the family (for example: configuration, side-by-side-extension, in-app-extension, integration)."
              },
              "bindingTime": {
                "type": "string",
                "enum": ["design", "decision", "build", "deployment", "runtime"]
              },
              "allowedValues": {
                "type": "array",
                "items": { "type": ["string", "number", "boolean"] }
              },
              "constraints": {
                "type": "array",
                "items": { "type": "string" }
              },
              "rationale": { "type": "string" }
            },
            "additionalProperties": true
          }
        },
        "rules": {
          "type": "array",
          "description": "Cross-variation-point rules. Each rule is a declarative constraint that links one variation point's value to required or forbidden values of others.",
          "items": {
            "type": "object",
            "properties": {
              "when": { "type": "string" },
              "require": {
                "type": "array",
                "items": { "type": "string" }
              },
              "forbid": {
                "type": "array",
                "items": { "type": "string" }
              }
            },
            "additionalProperties": true
          }
        },
        "exceptionPolicy": {
          "type": "object",
          "properties": {
            "allowed": { "type": "boolean" },
            "approverRole": { "type": "string" },
            "maxDurationDays": { "type": "integer", "minimum": 1 },
            "requiredCompensatingControl": { "type": "string" }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": false
}
