{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://zaroz.cloud/contract/units/v1/unit.schema.json",
  "title": "/zaroz/unit.json",
  "description": "Who this unit is. Labels update live; every other field is fixed for the life of the pod. Ignore fields you do not know.",
  "type": "object",
  "required": ["contract_version", "unit_id", "key", "labels", "origin", "workload", "project_id", "region", "private_name", "public_endpoints", "incarnation", "started_at"],
  "properties": {
    "contract_version": { "const": 1 },
    "unit_id": { "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 }
    },
    "origin": { "type": "string", "minLength": 1, "description": "How the unit came to exist (for example policy, code, warm)." },
    "workload": {
      "type": "object",
      "required": ["id", "slug"],
      "properties": { "id": { "type": "string", "minLength": 1 }, "slug": { "type": "string", "minLength": 1 } }
    },
    "project_id": { "type": "string", "minLength": 1 },
    "region": { "type": "string", "minLength": 1 },
    "private_name": { "type": "string", "minLength": 1, "description": "<key>.<workload>, resolvable from the project's other units." },
    "public_endpoints": {
      "type": "array",
      "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" }
        }
      }
    },
    "incarnation": { "type": "integer", "minimum": 0 },
    "started_at": { "type": "string", "format": "date-time" }
  }
}
