{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.anguskit.com/schema/angusmeter/plugins/angus-jdbc.json",
  "type": "object",
  "required": [
    "url",
    "query"
  ],
  "properties": {
    "url": {
      "type": "string",
      "description": "JDBC connection URL, e.g. jdbc:mysql://host:3306/db. Supports ${varName} interpolation."
    },
    "username": {
      "type": "string",
      "description": "Database username. Supports ${varName} interpolation."
    },
    "password": {
      "type": "string",
      "description": "Database password.",
      "writeOnly": true
    },
    "query": {
      "type": "string",
      "description": "SQL statement to execute. Supports ${varName} interpolation and ? positional parameters."
    },
    "queryType": {
      "type": "string",
      "enum": [
        "AUTO",
        "SELECT",
        "INSERT",
        "UPDATE",
        "DELETE",
        "MERGE",
        "CALL",
        "DDL"
      ],
      "default": "AUTO",
      "description": "SQL statement type. AUTO detects from query syntax (handles CTEs, comments, CALL, MERGE)."
    },
    "params": {
      "type": "array",
      "description": "Positional parameter values for ? placeholders. Supports ${varName} interpolation in string values.",
      "items": {}
    },
    "queryTimeout": {
      "type": "integer",
      "minimum": 0,
      "maximum": 600,
      "default": 30,
      "description": "Query execution timeout in seconds. 0 means no timeout."
    },
    "connectionTimeout": {
      "type": "integer",
      "minimum": 1,
      "maximum": 60,
      "default": 30,
      "description": "Timeout in seconds to acquire a connection from the pool."
    },
    "maxRows": {
      "type": "integer",
      "minimum": 1,
      "description": "Maximum rows to fetch per query. Prevents OOM on unexpectedly large result sets."
    },
    "fetchSize": {
      "type": "integer",
      "minimum": 1,
      "description": "JDBC fetch size hint — number of rows fetched per server round-trip (streaming large results)."
    },
    "autoCommit": {
      "type": "boolean",
      "default": true,
      "description": "Enable or disable JDBC auto-commit mode."
    },
    "isolation": {
      "type": "string",
      "enum": [
        "READ_UNCOMMITTED",
        "READ_COMMITTED",
        "REPEATABLE_READ",
        "SERIALIZABLE"
      ],
      "description": "Transaction isolation level. Defaults to the database's own default."
    },
    "resultFormat": {
      "type": "string",
      "enum": [
        "JSON_ARRAY",
        "JSON_OBJECT",
        "ROW_COUNT",
        "FIRST_VALUE"
      ],
      "default": "JSON_ARRAY",
      "description": "Output format for SELECT results. JSON_ARRAY=all rows as array (default), JSON_OBJECT=first row as object, ROW_COUNT=only {rowCount:N}, FIRST_VALUE=first column of first row."
    },
    "columnCase": {
      "type": "string",
      "enum": [
        "ORIGINAL",
        "LOWER",
        "UPPER"
      ],
      "default": "LOWER",
      "description": "Column name case in serialized JSON. ORIGINAL preserves driver-reported case (use for case-sensitive JSONPath like $[0].CustomerID). LOWER (default, backward-compatible) and UPPER normalize identifiers."
    },
    "maxPoolSize": {
      "type": "integer",
      "minimum": 1,
      "maximum": 50,
      "default": 10,
      "description": "Maximum number of connections in the pool per data source."
    },
    "minIdle": {
      "type": "integer",
      "minimum": 0,
      "default": 1,
      "description": "Minimum number of idle connections maintained in the pool."
    },
    "assertions": {
      "type": "array",
      "description": "Optional step-level assertions evaluated against the JDBC sample result (see JdbcConfigValidator).",
      "items": {
        "$ref": "#/definitions/jdbcAssertion"
      }
    },
    "extractors": {
      "type": "array",
      "description": "Optional extractors from the JDBC response body (see JdbcConfigValidator).",
      "items": {
        "$ref": "#/definitions/jdbcExtractor"
      }
    }
  },
  "definitions": {
    "jdbcAssertion": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "STATUS_CODE",
            "RESPONSE_TIME",
            "BODY_CONTAINS",
            "BODY_JSON_PATH",
            "BODY_REGEX",
            "BODY_EQUALS",
            "NOT_NULL",
            "CUSTOM"
          ]
        },
        "operator": {
          "type": "string"
        },
        "expected": {
          "description": "Expected value for the assertion"
        },
        "expression": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean"
        }
      },
      "required": [
        "type"
      ]
    },
    "jdbcExtractor": {
      "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"
      ]
    }
  }
}
