{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:orbiplex:schema:sensorium-virt.host.request:v1",
  "title": "Sensorium Virt Host Request v1",
  "description": "Bounded internal request envelope for daemon-owned Sensorium Virt host authority.",
  "type": "object",
  "additionalProperties": false,
  "x-dia-workflow": "project",
  "x-dia-status": "draft",
  "x-dia-basis": [
    "doc/project/40-proposals/071-sensorium-workbench.md"
  ],
  "required": [
    "schema",
    "schema/v",
    "operation",
    "payload"
  ],
  "properties": {
    "schema": {
      "const": "sensorium-virt.host.request.v1"
    },
    "schema/v": {
      "const": 1
    },
    "operation": {
      "enum": [
        "fixture.prepare",
        "vfkit.allocate",
        "environment.start",
        "environment.inspect",
        "environment.drain",
        "environment.teardown",
        "environment.recover",
        "host.reconcile"
      ]
    },
    "payload": {
      "type": "object"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "operation": {
            "const": "fixture.prepare"
          }
        },
        "required": [
          "operation"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "$ref": "#/$defs/fixturePrepare"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "operation": {
            "const": "vfkit.allocate"
          }
        },
        "required": [
          "operation"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "$ref": "#/$defs/vfkitAllocate"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "operation": {
            "enum": [
              "environment.inspect",
              "environment.start",
              "environment.drain",
              "environment.teardown",
              "environment.recover"
            ]
          }
        },
        "required": [
          "operation"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "$ref": "#/$defs/environmentBinding"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "operation": {
            "const": "host.reconcile"
          }
        },
        "required": [
          "operation"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "$ref": "#/$defs/emptyPayload"
          }
        }
      }
    }
  ],
  "$defs": {
    "ref": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "not": {
        "pattern": "\\u0000"
      }
    },
    "fixturePrepare": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source/path",
        "workspace/ref",
        "root/ref",
        "operational/context",
        "operational/context-policy-ref",
        "files/max",
        "bytes/max"
      ],
      "properties": {
        "source/path": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096,
          "not": {
            "pattern": "\\u0000"
          }
        },
        "workspace/ref": {
          "$ref": "#/$defs/ref"
        },
        "root/ref": {
          "$ref": "#/$defs/ref"
        },
        "idempotency/key": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "not": {
            "pattern": "\\u0000"
          }
        },
        "operational/context": {
          "$ref": "sensorium-operational-context.v1.schema.json"
        },
        "operational/context-policy-ref": {
          "$ref": "#/$defs/ref"
        },
        "files/max": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1024
        },
        "bytes/max": {
          "type": "integer",
          "minimum": 1,
          "maximum": 16777216
        }
      }
    },
    "environmentBinding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "environment/ref",
        "source/generation-ref"
      ],
      "properties": {
        "environment/ref": {
          "$ref": "#/$defs/ref"
        },
        "source/generation-ref": {
          "$ref": "#/$defs/ref"
        }
      }
    },
    "vfkitAllocate": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "workspace/ref",
        "root/ref",
        "operational/context",
        "operational/context-policy-ref",
        "limits"
      ],
      "properties": {
        "workspace/ref": {
          "$ref": "#/$defs/ref"
        },
        "root/ref": {
          "$ref": "#/$defs/ref"
        },
        "idempotency/key": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "not": {
            "pattern": "\\u0000"
          }
        },
        "operational/context": {
          "$ref": "sensorium-operational-context.v1.schema.json"
        },
        "operational/context-policy-ref": {
          "$ref": "#/$defs/ref"
        },
        "limits": {
          "$ref": "#/$defs/environmentLimits"
        }
      }
    },
    "environmentLimits": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "cpu/vcpus",
        "memory/bytes",
        "storage/bytes",
        "processes/max",
        "operation/timeout-ms",
        "channel/frame-bytes-max",
        "channel/queue-depth-max"
      ],
      "properties": {
        "cpu/vcpus": {
          "type": "integer",
          "minimum": 1,
          "maximum": 256
        },
        "memory/bytes": {
          "type": "integer",
          "minimum": 67108864,
          "maximum": 1099511627776,
          "multipleOf": 1048576
        },
        "storage/bytes": {
          "type": "integer",
          "minimum": 1048576,
          "maximum": 17592186044416
        },
        "processes/max": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1048576
        },
        "operation/timeout-ms": {
          "type": "integer",
          "minimum": 1,
          "maximum": 86400000
        },
        "channel/frame-bytes-max": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1048576
        },
        "channel/queue-depth-max": {
          "type": "integer",
          "minimum": 1,
          "maximum": 4096
        }
      }
    },
    "emptyPayload": {
      "type": "object",
      "additionalProperties": false,
      "maxProperties": 0
    }
  }
}
