{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.kxm.dev/gate-registry.schema.json",
  "title": "KXM gate registry",
  "type": "object",
  "required": [
    "schema",
    "gates"
  ],
  "properties": {
    "schema": {
      "const": "kxm.gate-registry.v1"
    },
    "gates": {
      "type": "object",
      "minProperties": 1,
      "maxProperties": 64,
      "propertyNames": {
        "$ref": "common.schema.json#/$defs/identifier"
      },
      "additionalProperties": {
        "oneOf": [
          {
            "$ref": "#/$defs/command"
          },
          {
            "$ref": "#/$defs/artifactsExist"
          },
          {
            "$ref": "#/$defs/reserved"
          }
        ]
      }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "command": {
      "type": "object",
      "required": [
        "kind",
        "argv",
        "timeoutMs"
      ],
      "properties": {
        "kind": {
          "const": "command"
        },
        "argv": {
          "type": "array",
          "minItems": 1,
          "maxItems": 64,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4096,
            "pattern": "^[^\\u0000]+$"
          }
        },
        "timeoutMs": {
          "type": "integer",
          "minimum": 1,
          "maximum": 2147483647
        },
        "cwd": {
          "const": "control"
        }
      },
      "additionalProperties": false
    },
    "artifactsExist": {
      "type": "object",
      "required": [
        "kind",
        "paths"
      ],
      "properties": {
        "kind": {
          "const": "artifacts-exist"
        },
        "paths": {
          "type": "array",
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true,
          "items": {
            "$ref": "common.schema.json#/$defs/relativePath",
            "not": {
              "const": "."
            }
          }
        }
      },
      "additionalProperties": false
    },
    "reserved": {
      "type": "object",
      "required": [
        "kind"
      ],
      "properties": {
        "kind": {
          "const": "reserved"
        }
      },
      "additionalProperties": false
    }
  }
}
