{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.glyphd.com/schemas/semantic-fractal-topology.command.schema.json",
  "title": "Semantic Fractal Topology Typed Command",
  "description": "Commands accepted by the public SFT deterministic dispatcher. Language compilation may produce one of these commands or refuse/return ambiguity.",
  "oneOf": [
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "objectId", "openingId", "allowRotation"],
      "properties": {
        "kind": { "const": "QUERY_FIT" },
        "objectId": { "$ref": "#/$defs/id" },
        "openingId": { "$ref": "#/$defs/id" },
        "allowRotation": { "type": "boolean" }
      }
    },
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind"],
      "properties": {
        "kind": { "const": "QUERY_COLLISION" },
        "scopeEntityId": { "$ref": "#/$defs/id" },
        "entityIds": { "type": "array", "items": { "$ref": "#/$defs/id" }, "uniqueItems": true }
      }
    },
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind"],
      "properties": {
        "kind": { "const": "VALIDATE_CONSTRAINTS" },
        "scopeEntityId": { "$ref": "#/$defs/id" }
      }
    },
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "fromId", "toId"],
      "properties": {
        "kind": { "const": "QUERY_REACHABILITY" },
        "fromId": { "$ref": "#/$defs/id" },
        "toId": { "$ref": "#/$defs/id" },
        "minimumClearance": { "$ref": "#/$defs/interval" }
      }
    },
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "assemblyId"],
      "properties": {
        "kind": { "const": "AUDIT_ASSEMBLY" },
        "assemblyId": { "$ref": "#/$defs/id" }
      }
    },
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "scopeEntityId", "policyId"],
      "properties": {
        "kind": { "const": "AUDIT_ARCHITECTURAL_CLEARANCE" },
        "scopeEntityId": { "$ref": "#/$defs/id" },
        "policyId": { "$ref": "#/$defs/id" }
      }
    },
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "targetId"],
      "properties": {
        "kind": { "const": "AUDIT_SERVICE_ACCESS" },
        "targetId": { "$ref": "#/$defs/id" }
      }
    },
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "entityId", "targetSpaceId"],
      "properties": {
        "kind": { "const": "MOVE_ENTITY" },
        "entityId": { "$ref": "#/$defs/id" },
        "targetSpaceId": { "$ref": "#/$defs/id" }
      }
    }
  ],
  "$defs": {
    "id": { "type": "string", "minLength": 1, "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$" },
    "lengthUnit": { "enum": ["mm", "cm", "m", "in", "ft"] },
    "interval": {
      "type": "object",
      "additionalProperties": false,
      "required": ["min", "max", "unit"],
      "properties": {
        "min": { "type": "number" },
        "max": { "type": "number" },
        "unit": { "$ref": "#/$defs/lengthUnit" }
      }
    }
  }
}
