{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.anguskit.com/schema/angusmeter/plugins/angus-udp.json",
  "type": "object",
  "properties": {
    "host": {
      "type": "string",
      "description": "Target hostname, IP, or multicast group address (supports ${var} interpolation)"
    },
    "port": {
      "type": "integer",
      "minimum": 1,
      "maximum": 65535,
      "description": "Target port number"
    },
    "message": {
      "type": "string",
      "description": "Payload data to send (supports ${var} interpolation)"
    },
    "encoding": {
      "type": "string",
      "default": "UTF-8",
      "description": "Character encoding for text mode"
    },
    "timeout": {
      "type": "integer",
      "minimum": 0,
      "default": 5000,
      "description": "Receive timeout in milliseconds"
    },
    "waitForResponse": {
      "type": "boolean",
      "default": false,
      "description": "Whether to wait for a response datagram"
    },
    "bufferSize": {
      "type": "integer",
      "minimum": 1,
      "default": 65535,
      "description": "Receive buffer size in bytes"
    },
    "mode": {
      "type": "string",
      "enum": [
        "text",
        "binary"
      ],
      "default": "text",
      "description": "Encoding mode: text (UTF-8) or binary (hex)"
    },
    "multicast": {
      "type": "object",
      "description": "Multicast configuration",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": false
        },
        "groupAddress": {
          "type": "string",
          "description": "Multicast group address (e.g. 224.0.0.1)"
        },
        "ttl": {
          "type": "integer",
          "minimum": 0,
          "maximum": 255,
          "default": 1,
          "description": "Time-to-live for multicast packets"
        },
        "networkInterface": {
          "type": "string",
          "description": "Network interface name for multicast (e.g. eth0)"
        }
      }
    },
    "broadcast": {
      "type": "boolean",
      "default": false,
      "description": "Enable broadcast mode (e.g. send to 255.255.255.255)"
    },
    "localPort": {
      "type": "integer",
      "minimum": 0,
      "maximum": 65535,
      "description": "Local port to bind (0 = ephemeral)"
    },
    "assertions": {
      "type": "array",
      "description": "Optional step-level assertions evaluated against the UDP sample result (see UdpConfigValidator).",
      "items": {
        "$ref": "#/definitions/udpAssertion"
      }
    },
    "extractors": {
      "type": "array",
      "description": "Optional extractors from the UDP response (see UdpConfigValidator).",
      "items": {
        "$ref": "#/definitions/udpExtractor"
      }
    },
    "maxDurationSeconds": {
      "type": "integer",
      "minimum": 1,
      "description": "Maximum duration in seconds for streaming/SSE mode. Only used with the stream() API."
    }
  },
  "required": [
    "host",
    "port"
  ],
  "definitions": {
    "udpAssertion": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "BODY_CONTAINS",
            "BODY_JSON_PATH",
            "STATUS_CODE",
            "RESPONSE_TIME"
          ]
        },
        "operator": {
          "type": "string",
          "enum": [
            "EQUALS",
            "NOT_EQUALS",
            "CONTAINS",
            "NOT_CONTAINS",
            "GREATER_THAN",
            "LESS_THAN",
            "GREATER_OR_EQUAL",
            "LESS_OR_EQUAL",
            "MATCHES_REGEX"
          ]
        },
        "expected": {
          "description": "Expected value for the assertion"
        },
        "expression": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean"
        }
      },
      "required": [
        "type"
      ]
    },
    "udpExtractor": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "JSON_PATH",
            "REGEX",
            "RESPONSE_CODE",
            "RESPONSE_TIME"
          ]
        },
        "expression": {
          "type": "string"
        },
        "variable": {
          "type": "string"
        },
        "defaultValue": {
          "type": "string"
        }
      },
      "required": [
        "type",
        "variable"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "JSON_PATH",
                  "REGEX"
                ]
              }
            }
          },
          "then": {
            "required": [
              "expression"
            ]
          }
        }
      ]
    }
  }
}
