{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.anguskit.com/schema/angusmeter/plugins/angus-tcp.json",
  "type": "object",
  "properties": {
    "host": {
      "type": "string",
      "description": "Target hostname or IP 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)"
    },
    "mode": {
      "type": "string",
      "enum": [
        "text",
        "binary"
      ],
      "default": "text",
      "description": "Encoding mode: text (UTF-8) or binary (hex)"
    },
    "timeout": {
      "type": "integer",
      "minimum": 0,
      "default": 5000,
      "description": "Connect and read timeout in milliseconds"
    },
    "encoding": {
      "type": "string",
      "default": "UTF-8",
      "description": "Character encoding for text mode"
    },
    "waitForResponse": {
      "type": "boolean",
      "default": true,
      "description": "Whether to wait and read a response"
    },
    "tls": {
      "type": "object",
      "description": "TLS/SSL configuration mapped to cloud.xcan.angus.spec.model.TlsConfig.",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": false
        },
        "trustAll": {
          "type": "boolean",
          "default": false,
          "description": "Trust all certificates (testing only)"
        },
        "verifyHostname": {
          "type": "boolean",
          "default": true,
          "description": "Whether to verify server hostname against certificate CN/SANs"
        },
        "truststorePath": {
          "type": "string",
          "description": "Path to trust store (JKS/PKCS12). Store format is inferred from the extension."
        },
        "truststorePassword": {
          "type": "string",
          "writeOnly": true
        },
        "keystorePath": {
          "type": "string",
          "description": "Path to client keystore (JKS/PKCS12) for mTLS. Store format is inferred from the extension."
        },
        "keystorePassword": {
          "type": "string",
          "writeOnly": true
        },
        "certPath": {
          "type": "string",
          "description": "Path to PEM client certificate (mTLS). Must be combined with keyPath."
        },
        "keyPath": {
          "type": "string",
          "description": "Path to PEM private key. Must be combined with certPath."
        },
        "keyPassword": {
          "type": "string",
          "writeOnly": true,
          "description": "Password for encrypted PEM private key."
        },
        "caPath": {
          "type": "string",
          "description": "Path to CA bundle (PEM) used as trust anchors."
        },
        "protocols": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Enabled TLS protocols, e.g. TLSv1.2, TLSv1.3."
        },
        "ciphers": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Enabled cipher suites."
        }
      }
    },
    "readStrategy": {
      "type": "string",
      "enum": [
        "single",
        "delimiter",
        "length",
        "close"
      ],
      "default": "single",
      "description": "How to read the response: single (one read), delimiter (read until delimiter), length (read N bytes), close (read until connection closes)"
    },
    "delimiter": {
      "type": "string",
      "default": "\n",
      "description": "Delimiter for 'delimiter' read strategy (e.g. '\\n' for newline)"
    },
    "readLength": {
      "type": "integer",
      "minimum": 1,
      "description": "Number of bytes for 'length' read strategy"
    },
    "receiveBufferSize": {
      "type": "integer",
      "minimum": 1,
      "default": 65536,
      "description": "Socket receive buffer size"
    },
    "keepAlive": {
      "type": "boolean",
      "default": false,
      "description": "Reuse TCP connection across samples"
    },
    "tcpNoDelay": {
      "type": "boolean",
      "default": true,
      "description": "Set TCP_NODELAY (disable Nagle)"
    },
    "assertions": {
      "type": "array",
      "description": "Optional step-level assertions evaluated against the TCP sample result (see TcpConfigValidator).",
      "items": {
        "$ref": "#/definitions/tcpAssertion"
      }
    },
    "extractors": {
      "type": "array",
      "description": "Optional extractors from the TCP response (see TcpConfigValidator).",
      "items": {
        "$ref": "#/definitions/tcpExtractor"
      }
    },
    "maxDurationSeconds": {
      "type": "integer",
      "minimum": 1,
      "description": "Maximum duration in seconds for streaming/SSE mode. Only used with the stream() API."
    },
    "readChunkBytes": {
      "type": "integer",
      "minimum": 1,
      "description": "Number of bytes to read per chunk in streaming mode."
    }
  },
  "required": [
    "host",
    "port"
  ],
  "definitions": {
    "tcpAssertion": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "Label for reporting"
        },
        "type": {
          "type": "string",
          "enum": [
            "STATUS_CODE",
            "RESPONSE_TIME",
            "BODY_CONTAINS",
            "BODY_JSON_PATH",
            "BODY_REGEX",
            "HEADER_EXISTS",
            "HEADER_VALUE",
            "BODY_SIZE",
            "NOT_NULL",
            "CUSTOM",
            "BODY_EQUALS",
            "BODY_XPATH"
          ]
        },
        "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 (type depends on assertion)"
        },
        "expression": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean"
        }
      },
      "required": [
        "type"
      ]
    },
    "tcpExtractor": {
      "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",
        "expression",
        "variable"
      ]
    }
  }
}
