{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.anguskit.com/schema/angusmeter/plugins/angus-smtp.json",
  "type": "object",
  "properties": {
    "host": {
      "type": "string",
      "description": "SMTP server hostname (supports ${var} interpolation)"
    },
    "port": {
      "type": "integer",
      "minimum": 1,
      "maximum": 65535,
      "default": 25,
      "description": "SMTP server port"
    },
    "from": {
      "type": "string",
      "description": "Sender email address (supports ${var} interpolation)"
    },
    "to": {
      "type": "string",
      "description": "Primary recipient email address (supports ${var} interpolation)"
    },
    "cc": {
      "type": "string",
      "description": "CC recipients, comma-separated (supports ${var} interpolation)"
    },
    "bcc": {
      "type": "string",
      "description": "BCC recipients, comma-separated (supports ${var} interpolation)"
    },
    "subject": {
      "type": "string",
      "description": "Email subject (supports ${var} interpolation)"
    },
    "body": {
      "type": "string",
      "description": "Email body content (supports ${var} interpolation)"
    },
    "contentType": {
      "type": "string",
      "enum": [
        "text/plain",
        "text/html"
      ],
      "default": "text/plain",
      "description": "MIME content type"
    },
    "username": {
      "type": "string",
      "description": "SMTP AUTH username (supports ${var} interpolation)"
    },
    "password": {
      "type": "string",
      "writeOnly": true,
      "description": "SMTP AUTH password (supports ${var} interpolation)"
    },
    "timeout": {
      "type": "integer",
      "minimum": 0,
      "default": 10000,
      "description": "Socket timeout in milliseconds"
    },
    "tls": {
      "type": "object",
      "description": "STARTTLS configuration. All fields are mapped through cloud.xcan.angus.spec.model.TlsConfig; provide keystore/truststore or PEM cert+key to enable mutual TLS.",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": false,
          "description": "Enable STARTTLS"
        },
        "trustAll": {
          "type": "boolean",
          "default": false,
          "description": "Trust all certificates (testing only)"
        },
        "verifyHostname": {
          "type": "boolean",
          "default": true,
          "description": "Verify SMTP server hostname against the certificate (effective when trustAll=false)"
        },
        "keystorePath": {
          "type": "string",
          "description": "Path to client keystore (JKS/PKCS12) for mTLS. Store format is inferred from the extension."
        },
        "keystorePassword": {
          "type": "string",
          "description": "Client keystore password.",
          "writeOnly": true
        },
        "truststorePath": {
          "type": "string",
          "description": "Path to custom trust store (JKS/PKCS12)."
        },
        "truststorePassword": {
          "type": "string",
          "description": "Trust store password.",
          "writeOnly": true
        },
        "certPath": {
          "type": "string",
          "description": "PEM client certificate path (used with keyPath for mTLS)."
        },
        "keyPath": {
          "type": "string",
          "description": "PEM PKCS#8 private key path (used with certPath)."
        },
        "keyPassword": {
          "type": "string",
          "description": "Password for encrypted PEM private key.",
          "writeOnly": true
        },
        "caPath": {
          "type": "string",
          "description": "PEM CA bundle path (alternative to truststorePath)."
        },
        "protocols": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Allowed TLS protocol versions."
        },
        "ciphers": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Allowed cipher suites."
        }
      }
    },
    "assertions": {
      "type": "array",
      "description": "Optional step-level assertions evaluated against the SMTP sample result (see SmtpConfigValidator).",
      "items": {
        "$ref": "#/definitions/smtpAssertion"
      }
    },
    "extractors": {
      "type": "array",
      "description": "Optional extractors from the SMTP response (see SmtpConfigValidator).",
      "items": {
        "$ref": "#/definitions/smtpExtractor"
      }
    }
  },
  "required": [
    "host",
    "from",
    "to"
  ],
  "definitions": {
    "smtpAssertion": {
      "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"
          ]
        },
        "operator": {
          "type": "string"
        },
        "expected": {
          "description": "Expected value for the assertion"
        },
        "expression": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean"
        }
      },
      "required": [
        "type"
      ]
    },
    "smtpExtractor": {
      "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"
            ]
          }
        }
      ]
    }
  }
}
