{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/evolution/domain-evolution-decision.v1.schema.json",
  "title": "RootBlocks Domain Evolution Decision v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "decisionId",
    "standard",
    "status",
    "decisionType",
    "risk",
    "targets",
    "inputs",
    "recommendation",
    "gates",
    "evidence"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.domain-evolution-decision/v1"
    },
    "decisionId": {
      "$ref": "#/$defs/id"
    },
    "standard": {
      "$ref": "#/$defs/standardRef"
    },
    "status": {
      "enum": ["proposed", "approved", "rejected", "blocked", "request-more-monitoring", "superseded", "completed"]
    },
    "decisionType": {
      "enum": [
        "scale-horizontal",
        "scale-vertical",
        "add-cache",
        "remove-cache",
        "add-queue",
        "add-stream",
        "add-backpressure",
        "separate-read-write-model",
        "add-read-replica",
        "partition-data",
        "shard-data",
        "split-bounded-context",
        "split-service",
        "split-component",
        "split-workflow",
        "merge-components",
        "merge-services",
        "migrate-database",
        "migrate-cache",
        "migrate-queue",
        "migrate-search",
        "migrate-runtime",
        "migrate-hosting",
        "block"
      ]
    },
    "risk": {
      "enum": ["low", "medium", "high", "critical"]
    },
    "targets": {
      "$ref": "#/$defs/targets"
    },
    "inputs": {
      "$ref": "#/$defs/inputs"
    },
    "evaluation": {
      "$ref": "#/$defs/evaluation"
    },
    "recommendation": {
      "$ref": "#/$defs/recommendation"
    },
    "gates": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/gate"
      }
    },
    "evidence": {
      "$ref": "#/$defs/evidencePolicy"
    },
    "execution": {
      "$ref": "#/$defs/executionState"
    }
  },
  "$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}$"
    },
    "path": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_./@-]+$"
    },
    "standardRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["bundleId", "version", "hash"],
      "properties": {
        "bundleId": {
          "$ref": "#/$defs/id"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "hash": {
          "$ref": "#/$defs/hash"
        }
      }
    },
    "targets": {
      "type": "object",
      "additionalProperties": false,
      "required": ["domainIds"],
      "properties": {
        "domainIds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/id"
          },
          "uniqueItems": true
        },
        "boundedContextIds": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/id"
          },
          "uniqueItems": true
        },
        "workflowIds": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/id"
          },
          "uniqueItems": true
        },
        "componentIds": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/id"
          },
          "uniqueItems": true
        },
        "dataResourceIds": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/id"
          },
          "uniqueItems": true
        }
      }
    },
    "inputs": {
      "type": "object",
      "additionalProperties": false,
      "required": ["signalRefs", "domainRegistryRefs", "evidenceRefs"],
      "properties": {
        "signalRefs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/id"
          },
          "uniqueItems": true
        },
        "domainRegistryRefs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/path"
          },
          "uniqueItems": true
        },
        "dataConstructionRefs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/path"
          },
          "uniqueItems": true
        },
        "evidenceRefs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/path"
          },
          "uniqueItems": true
        }
      }
    },
    "evaluation": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "technicalHealth": {
          "enum": ["healthy", "watch", "degraded", "critical"]
        },
        "businessHealth": {
          "enum": ["healthy", "watch", "degraded", "critical"]
        },
        "complexity": {
          "enum": ["low", "medium", "high"]
        },
        "cost": {
          "enum": ["acceptable", "watch", "high", "critical"]
        },
        "risk": {
          "enum": ["low", "medium", "high", "critical"]
        },
        "maturity": {
          "enum": ["insufficient", "partial", "ready"]
        }
      }
    },
    "recommendation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["action", "summary", "expectedBenefit", "executionAllowed"],
      "properties": {
        "action": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
        },
        "summary": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "strategy": {
          "enum": ["rolling", "blue-green", "strangler-fig", "expand-contract", "feature-flag", "manual", "none"]
        },
        "expectedBenefit": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "executionAllowed": {
          "type": "boolean"
        }
      }
    },
    "gate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "type", "required", "evidenceRequired"],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "enum": ["approval", "rollback", "regression", "observability", "compatibility", "data-ownership", "release", "cost-review"]
        },
        "required": {
          "type": "boolean"
        },
        "evidenceRequired": {
          "type": "boolean"
        }
      }
    },
    "evidencePolicy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["required", "evidenceRefs"],
      "properties": {
        "required": {
          "const": true
        },
        "evidenceRefs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/path"
          },
          "uniqueItems": true
        }
      }
    },
    "executionState": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state"],
      "properties": {
        "state": {
          "enum": ["not-started", "planned", "executed"]
        },
        "releaseEvidenceRefs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/path"
          }
        }
      }
    }
  }
}
