{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/sklarsa/incus-azure-pipelines/config-schema.json",
  "$ref": "#/$defs/CmdCLIConfig",
  "$defs": {
    "CmdCLIConfig": {
      "properties": {
        "pools": {
          "items": {
            "$ref": "#/$defs/PoolConfig"
          },
          "type": "array",
          "description": "Pools is the list of agent pools to manage."
        },
        "metricsPort": {
          "type": "integer",
          "description": "MetricsPort is the port number that serves Prometheus metrics. Default: 9922"
        },
        "daemon": {
          "$ref": "#/$defs/DaemonConfig",
          "description": "Daemon contains settings for the background daemon processes."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "description": "CLIConfig is the top-level configuration for the daemon."
    },
    "DaemonConfig": {
      "properties": {
        "reaperInterval": {
          "type": "integer",
          "description": "ReaperInterval is how often to check for and clean up stale agents. Default: 30s"
        },
        "reconcileInterval": {
          "type": "integer",
          "description": "ReconcileInterval is how often to reconcile expected vs actual agent count. Default: 5s"
        },
        "listener": {
          "$ref": "#/$defs/DaemonListenerConfig",
          "description": "Listener contains settings for the event listener."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "description": "Config contains settings for daemon background processes."
    },
    "DaemonListenerConfig": {
      "properties": {
        "retryDelay": {
          "type": "integer",
          "description": "RetryDelay is the initial delay between retries. Default: 1s"
        },
        "maxRetryDelay": {
          "type": "integer",
          "description": "MaxRetryDelay is the maximum delay between retries. Default: 1m"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "description": "ListenerConfig contains settings for event listener retry behavior."
    },
    "PoolAzureConfig": {
      "properties": {
        "pat": {
          "type": "string",
          "description": "PAT is an Azure Devops personal access token used for registering the agents"
        },
        "url": {
          "type": "string",
          "description": "Url of the server. For example: https://dev.azure.com/myorganization or http://my-azure-devops-server:8080/tfs"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "pat",
        "url"
      ]
    },
    "PoolConfig": {
      "properties": {
        "agentCount": {
          "type": "integer",
          "description": "AgentCount is the number of agents to run on this node"
        },
        "agentPrefix": {
          "type": "string",
          "description": "AgentPrefix overrides the hostname used for Azure agent naming.\nIf not set, defaults to the machine's hostname.\nMust be unique per host to avoid agent name collisions."
        },
        "azure": {
          "$ref": "#/$defs/PoolAzureConfig",
          "description": "Azure specific settings"
        },
        "incus": {
          "$ref": "#/$defs/PoolIncusConfig",
          "description": "Incus specific settings"
        },
        "env": {
          "additionalProperties": {
            "type": "string"
          },
          "type": "object",
          "description": "Env is a map of environment variables to set when running the agent."
        },
        "name": {
          "type": "string",
          "description": "Name is the name of the Azure Devops pool to run agents for.\nThis is also used to name running containers."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "agentCount",
        "azure",
        "incus",
        "name"
      ]
    },
    "PoolIncusConfig": {
      "properties": {
        "maxCores": {
          "type": "integer",
          "description": "MaxCores specifies the max number of cores that each agent can use. Used to set limits.cpu.allowance\nfor percentage-based soft limits"
        },
        "maxRamInGb": {
          "type": "integer",
          "description": "MaxRamInGb specifies the max amount of RAM that each agent can use"
        },
        "tmpfsSizeInGb": {
          "type": "integer",
          "description": "TmpfsSizeInGb specifies the maximum size of the tmpfs directory mounted to /tmp in each agent container"
        },
        "projectName": {
          "type": "string",
          "description": "ProjectName is the name of the incus project used for Azure Pipelines Agent runners"
        },
        "image": {
          "type": "string",
          "description": "Image is the Incus image alias to use for agent containers"
        },
        "startupGracePeriod": {
          "type": "integer",
          "description": "StartupGracePeriod is how long to wait before considering an agent stale"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "image"
      ]
    }
  },
  "title": "incus-azure-pipelines configuration",
  "description": "Configuration file schema for incus-azure-pipelines daemon"
}
