{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://zaroz.cloud/contract/units/v1/unit-signal-spec.schema.json",
  "title": "UnitSignal (units.zaroz.cloud/v1) spec",
  "description": "Written by the kernel, read by the agent. The agent ignores unknown fields and refuses a spec that fails validation, keeping the previous contract.",
  "type": "object",
  "required": ["unitId", "key", "contractVersion", "generation"],
  "properties": {
    "unitId": { "type": "string", "minLength": 1, "maxLength": 128 },
    "key": { "type": "string", "minLength": 1, "maxLength": 40, "pattern": "^[a-z0-9]([a-z0-9-]*[a-z0-9])?$" },
    "labels": {
      "type": "object",
      "maxProperties": 16,
      "propertyNames": { "minLength": 1, "maxLength": 32, "pattern": "^[a-z0-9]([a-z0-9_.-]*[a-z0-9])?$" },
      "additionalProperties": { "type": "string", "maxLength": 64 }
    },
    "userData": { "description": "Any JSON value, null for none." },
    "allocation": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "required": ["id", "generation"],
          "properties": {
            "id": { "type": "string", "minLength": 1, "maxLength": 128 },
            "generation": { "type": "integer" },
            "allocatedAt": { "type": "string", "format": "date-time", "description": "Optional; the agent stamps the time it first saw the allocation when absent." }
          }
        }
      ]
    },
    "draining": { "oneOf": [{ "const": false }, { "enum": ["stop", "destroy", "replace", "scale_down"] }], "description": "false, or the reason." },
    "contractVersion": { "const": 1 },
    "generation": { "type": "integer", "minimum": 0, "description": "Bump on every change; the agent acknowledges it in status.observedGeneration after the files are written." },
    "publicEndpoints": {
      "type": "array",
      "description": "Optional override of the pod's ZAROZ_PUBLIC_ENDPOINTS, for an address assigned after pod creation.",
      "items": {
        "type": "object",
        "required": ["protocols", "internal_port", "address"],
        "properties": {
          "protocols": { "type": "array", "items": { "type": "string" } },
          "internal_port": { "type": "integer", "minimum": 1, "maximum": 65535 },
          "address": { "type": "string" }
        }
      }
    }
  }
}
