{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.anguskit.com/schema/angusmeter/plugins/angus-kafka.json",
  "type": "object",
  "properties": {
    "bootstrapServers": {
      "type": "string",
      "description": "Comma-separated list of broker addresses (e.g. host1:9092,host2:9092)"
    },
    "topic": {
      "type": "string",
      "description": "Kafka topic name"
    },
    "key": {
      "type": "string",
      "description": "Message key (supports ${var} interpolation)"
    },
    "value": {
      "type": "string",
      "description": "Message value / payload (supports ${var} interpolation)"
    },
    "action": {
      "type": "string",
      "enum": [
        "produce",
        "consume"
      ],
      "default": "produce",
      "description": "Operation to perform"
    },
    "partition": {
      "type": "integer",
      "minimum": 0,
      "description": "Target partition (produce only, optional)"
    },
    "headers": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "Kafka message headers as key-value pairs"
    },
    "groupId": {
      "type": "string",
      "description": "Consumer group ID",
      "default": "angus-consumer"
    },
    "autoOffsetReset": {
      "type": "string",
      "enum": [
        "earliest",
        "latest",
        "none"
      ],
      "default": "earliest"
    },
    "maxPollRecords": {
      "type": "integer",
      "minimum": 1,
      "default": 1,
      "description": "Max records per poll"
    },
    "pollTimeout": {
      "type": "integer",
      "minimum": 100,
      "maximum": 60000,
      "default": 5000,
      "description": "Consumer poll timeout in ms"
    },
    "acks": {
      "type": "string",
      "enum": [
        "all",
        "1",
        "0"
      ],
      "default": "all"
    },
    "autoCommit": {
      "type": "boolean",
      "default": true,
      "description": "Enable auto-commit for consumer"
    },
    "security": {
      "type": "object",
      "description": "Security configuration for SASL/TLS",
      "properties": {
        "protocol": {
          "type": "string",
          "enum": [
            "PLAINTEXT",
            "SSL",
            "SASL_PLAINTEXT",
            "SASL_SSL"
          ],
          "default": "PLAINTEXT"
        },
        "mechanism": {
          "type": "string",
          "description": "SASL mechanism (e.g. PLAIN, SCRAM-SHA-256, SCRAM-SHA-512)"
        },
        "jaasConfig": {
          "type": "string",
          "description": "JAAS login config string"
        },
        "truststore": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string"
            },
            "password": {
              "type": "string",
              "writeOnly": true
            }
          }
        },
        "keystore": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string"
            },
            "password": {
              "type": "string",
              "writeOnly": true
            }
          }
        }
      }
    },
    "assertions": {
      "type": "array",
      "description": "Optional step-level assertions evaluated against the Kafka sample result (see KafkaConfigValidator; Assertion.AssertionType).",
      "items": {
        "$ref": "#/definitions/kafkaAssertion"
      }
    },
    "extractors": {
      "type": "array",
      "description": "Optional extractors from the Kafka response (see KafkaConfigValidator; Extractor.ExtractorType).",
      "items": {
        "$ref": "#/definitions/kafkaExtractor"
      }
    },
    "properties": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "Additional Kafka client properties (compression.type, linger.ms, batch.size, etc.)"
    }
  },
  "required": [
    "bootstrapServers",
    "topic"
  ],
  "definitions": {
    "kafkaAssertion": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "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",
            "METRIC_SCORE",
            "TOKEN_COUNT",
            "API_COST",
            "LLM_LATENCY",
            "JSON_SCHEMA",
            "NO_PII",
            "RESPONSE_BODY",
            "URL",
            "TITLE",
            "ELEMENT_TEXT",
            "ELEMENT_VALUE",
            "ELEMENT_VISIBLE",
            "ORIENTATION"
          ]
        },
        "operator": {
          "type": "string"
        },
        "expected": {
          "description": "Expected value for the assertion"
        },
        "expression": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean"
        }
      },
      "required": [
        "type"
      ]
    },
    "kafkaExtractor": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "JSON_PATH",
            "XPATH",
            "REGEX",
            "HEADER",
            "COOKIE",
            "RESPONSE_CODE",
            "RESPONSE_TIME"
          ]
        },
        "expression": {
          "type": "string"
        },
        "variable": {
          "type": "string"
        },
        "defaultValue": {
          "type": "string"
        }
      },
      "required": [
        "type",
        "variable"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "JSON_PATH",
                  "XPATH",
                  "REGEX",
                  "HEADER",
                  "COOKIE"
                ]
              }
            }
          },
          "then": {
            "required": [
              "expression"
            ]
          }
        }
      ]
    }
  }
}
