{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.anguskit.com/schema/angusmeter/plugins/angus-redis.json",
  "type": "object",
  "properties": {
    "host": {
      "type": "string",
      "default": "localhost",
      "description": "Redis server hostname"
    },
    "port": {
      "type": "integer",
      "default": 6379,
      "minimum": 1,
      "maximum": 65535,
      "description": "Redis server port"
    },
    "password": {
      "type": "string",
      "writeOnly": true,
      "description": "Redis authentication password"
    },
    "database": {
      "type": "integer",
      "default": 0,
      "minimum": 0,
      "maximum": 15,
      "description": "Redis database index"
    },
    "action": {
      "type": "string",
      "enum": [
        "GET",
        "SET",
        "DEL",
        "EXISTS",
        "EXPIRE",
        "TTL",
        "KEYS",
        "MGET",
        "MSET",
        "INCR",
        "DECR",
        "INCRBY",
        "DECRBY",
        "HGET",
        "HSET",
        "HDEL",
        "HGETALL",
        "HEXISTS",
        "LPUSH",
        "RPUSH",
        "LPOP",
        "RPOP",
        "LRANGE",
        "LLEN",
        "SADD",
        "SREM",
        "SMEMBERS",
        "SISMEMBER",
        "SCARD",
        "ZADD",
        "ZREM",
        "ZRANGE",
        "ZRANGEBYSCORE",
        "ZSCORE",
        "ZCARD",
        "PIPELINE",
        "EVAL",
        "PING",
        "INFO",
        "DBSIZE",
        "FLUSHDB",
        "APPEND",
        "GETRANGE",
        "SETEX",
        "SETNX",
        "TYPE"
      ],
      "default": "GET",
      "description": "Redis command to execute"
    },
    "key": {
      "type": "string",
      "description": "Redis key (supports ${var} interpolation)"
    },
    "value": {
      "type": "string",
      "description": "Value for write operations (supports ${var} interpolation)"
    },
    "field": {
      "type": "string",
      "description": "Hash field name for HGET/HSET/HDEL/HEXISTS"
    },
    "timeout": {
      "type": "integer",
      "default": 5000,
      "minimum": 100,
      "maximum": 60000,
      "description": "Connection timeout in ms"
    },
    "useSsl": {
      "type": "boolean",
      "default": false,
      "description": "Enable TLS/SSL connection"
    },
    "entries": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "Key-value pairs for MSET/MGET/PIPELINE operations"
    },
    "start": {
      "type": "integer",
      "default": 0,
      "description": "Start index for LRANGE/ZRANGE/GETRANGE"
    },
    "stop": {
      "type": "integer",
      "default": -1,
      "description": "Stop index for LRANGE/ZRANGE/GETRANGE"
    },
    "score": {
      "type": "number",
      "default": 0,
      "description": "Score for ZADD"
    },
    "expireSeconds": {
      "type": "integer",
      "default": -1,
      "description": "TTL in seconds for SET/EXPIRE/SETEX (-1 = no expiry)"
    },
    "script": {
      "type": "string",
      "description": "Lua script for EVAL command"
    },
    "args": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Arguments for EVAL command"
    },
    "sentinel": {
      "type": "object",
      "description": "Redis Sentinel configuration",
      "properties": {
        "masterName": {
          "type": "string",
          "description": "Sentinel master name"
        },
        "sentinels": {
          "type": "string",
          "description": "Comma-separated sentinel addresses (host1:port1,host2:port2)"
        }
      },
      "required": [
        "masterName",
        "sentinels"
      ]
    },
    "assertions": {
      "type": "array",
      "description": "Optional step-level assertions evaluated against the Redis sample result (see RedisConfigValidator). BODY is an alias for RESPONSE_BODY.",
      "items": {
        "$ref": "#/definitions/redisAssertion"
      }
    },
    "extractors": {
      "type": "array",
      "description": "Optional extractors from the Redis response JSON (see RedisConfigValidator).",
      "items": {
        "$ref": "#/definitions/redisExtractor"
      }
    }
  },
  "required": [
    "host"
  ],
  "definitions": {
    "redisAssertion": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "STATUS_CODE",
            "RESPONSE_TIME",
            "BODY_CONTAINS",
            "BODY_EQUALS",
            "BODY_JSON_PATH",
            "BODY_REGEX",
            "BODY_XPATH",
            "BODY_SIZE",
            "HEADER_EXISTS",
            "HEADER_VALUE",
            "NOT_NULL",
            "CUSTOM",
            "RESPONSE_BODY",
            "BODY"
          ]
        },
        "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"
      ]
    },
    "redisExtractor": {
      "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"
            ]
          }
        }
      ]
    }
  }
}
