{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.anguskit.com/schema/angusmeter/plugins/angus-ldap.json",
  "type": "object",
  "properties": {
    "url": {
      "type": "string",
      "description": "LDAP server URL (e.g. ldap://host:389 or ldaps://host:636)",
      "default": "ldap://localhost:389"
    },
    "baseDn": {
      "type": "string",
      "description": "Base DN for search operations",
      "default": ""
    },
    "action": {
      "type": "string",
      "enum": [
        "SEARCH",
        "BIND",
        "ADD",
        "MODIFY",
        "DELETE",
        "COMPARE"
      ],
      "default": "SEARCH",
      "description": "LDAP operation to perform"
    },
    "bindDn": {
      "type": "string",
      "description": "Bind DN for authentication"
    },
    "bindPassword": {
      "type": "string",
      "description": "Bind password",
      "writeOnly": true
    },
    "filter": {
      "type": "string",
      "description": "LDAP search filter",
      "default": "(objectClass=*)"
    },
    "searchScope": {
      "type": "string",
      "enum": [
        "OBJECT",
        "ONELEVEL",
        "SUBTREE"
      ],
      "default": "SUBTREE",
      "description": "Search scope"
    },
    "returnAttributes": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Attributes to return in search results"
    },
    "sizeLimit": {
      "type": "integer",
      "minimum": 0,
      "default": 0,
      "description": "Maximum entries to return (0 = no limit)"
    },
    "timeLimit": {
      "type": "integer",
      "minimum": 0,
      "default": 0,
      "description": "Search time limit in ms (0 = no limit)"
    },
    "timeout": {
      "type": "integer",
      "minimum": 1,
      "default": 10000,
      "description": "Connection/read timeout in ms"
    },
    "entryDn": {
      "type": "string",
      "description": "DN of entry for ADD/MODIFY/DELETE operations"
    },
    "attributes": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "Attributes for ADD/MODIFY operations"
    },
    "modifyOperation": {
      "type": "string",
      "enum": [
        "ADD",
        "REPLACE",
        "REMOVE"
      ],
      "default": "REPLACE",
      "description": "Modification type for MODIFY action"
    },
    "compareDn": {
      "type": "string",
      "description": "DN for COMPARE operation"
    },
    "compareAttribute": {
      "type": "string",
      "description": "Attribute name for COMPARE"
    },
    "compareValue": {
      "type": "string",
      "description": "Expected value for COMPARE"
    },
    "useSsl": {
      "type": "boolean",
      "default": false,
      "description": "Use LDAPS (SSL)"
    },
    "trustAll": {
      "type": "boolean",
      "default": false,
      "description": "Trust all certificates"
    },
    "assertions": {
      "type": "array",
      "description": "Optional step-level assertions against the LDAP sample result (see LdapConfigValidator).",
      "items": {
        "$ref": "#/definitions/ldapAssertion"
      }
    },
    "extractors": {
      "type": "array",
      "description": "Optional extractors from the LDAP response (see LdapConfigValidator).",
      "items": {
        "$ref": "#/definitions/ldapExtractor"
      }
    }
  },
  "required": [
    "url"
  ],
  "definitions": {
    "ldapAssertion": {
      "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"
          ]
        },
        "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"
      ]
    },
    "ldapExtractor": {
      "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"
            ]
          }
        }
      ]
    }
  }
}
