{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://portmux.dev/schema/portmux.config.json",
  "title": "PortMux Project Configuration",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string",
      "description": "Optional local or remote JSON Schema reference for editor intellisense."
    },
    "runner": {
      "$ref": "#/$defs/runner"
    },
    "groups": {
      "type": "object",
      "minProperties": 1,
      "description": "Group definitions keyed by group name.",
      "patternProperties": {
        "^.*$": {
          "$ref": "#/$defs/group"
        }
      },
      "additionalProperties": false
    }
  },
  "required": ["groups"],
  "$defs": {
    "runner": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "mode": {
          "type": "string",
          "enum": ["background"],
          "description": "Execution mode for commands."
        }
      },
      "required": ["mode"]
    },
    "group": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "description": {
          "type": "string",
          "description": "Human readable description of the group."
        },
        "commands": {
          "type": "array",
          "minItems": 1,
          "description": "List of commands to run in this group.",
          "items": {
            "$ref": "#/$defs/command"
          }
        }
      },
      "required": ["description", "commands"]
    },
    "command": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Unique command name."
        },
        "command": {
          "type": "string",
          "minLength": 1,
          "description": "Shell command to execute."
        },
        "ports": {
          "type": "array",
          "items": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 1
              },
              {
                "type": "string",
                "pattern": "^\\$\\{[^}]+\\}$"
              },
              {
                "type": "string",
                "pattern": "^[0-9]+$"
              }
            ]
          },
          "description": "Ports the command binds to (supports ${VAR} placeholders)."
        },
        "cwd": {
          "type": "string",
          "description": "Working directory for the command."
        },
        "env": {
          "type": "object",
          "description": "Environment variables for the command.",
          "additionalProperties": {
            "type": "string"
          }
        }
      },
      "required": ["name", "command"]
    }
  }
}
