{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://overdeck.local/spec/fleet.schema.json",
  "title": "fleet.json",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "nodes", "fallback"],
  "properties": {
    "schema_version": {
      "type": "integer",
      "const": 1
    },
    "nodes": {
      "type": "object",
      "additionalProperties": { "$ref": "#/definitions/node" },
      "minProperties": 1
    },
    "fallback": { "$ref": "#/definitions/fallback" }
  },
  "definitions": {
    "node": {
      "type": "object",
      "additionalProperties": false,
      "required": ["transport", "roles", "profiles"],
      "properties": {
        "transport": {
          "type": "string",
          "enum": ["local", "ssh"]
        },
        "host_ref": {
          "type": "string",
          "minLength": 1
        },
        "roles": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["control", "agent-runtime", "builder"]
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "profiles": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["shared-agent-tools", "workstation", "buildbox", "buildbox-root"]
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "execution": {
          "type": "string",
          "enum": ["normal", "last-resort", "none"]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": { "transport": { "const": "ssh" } },
            "required": ["transport"]
          },
          "then": { "required": ["host_ref"] }
        }
      ]
    },
    "fallback": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled",
        "node",
        "requires_all_unavailable",
        "max_concurrent_local_jobs",
        "activation_windows",
        "health_window_sec",
        "lease_ttl_sec"
      ],
      "properties": {
        "enabled": { "type": "boolean" },
        "node": { "type": "string", "minLength": 1 },
        "requires_all_unavailable": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "max_concurrent_local_jobs": { "type": "integer", "minimum": 0 },
        "activation_windows": { "type": "integer", "minimum": 1 },
        "health_window_sec": { "type": "integer", "minimum": 1 },
        "lease_ttl_sec": { "type": "integer", "minimum": 1 }
      }
    }
  }
}
