{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.anguskit.com/schema/angusmeter/plugins/angus-imap.json",
  "type": "object",
  "properties": {
    "host": {
      "type": "string",
      "description": "IMAP server hostname",
      "default": "localhost"
    },
    "port": {
      "type": "integer",
      "minimum": 1,
      "maximum": 65535,
      "default": 143,
      "description": "Server port (143 for IMAP, 993 for IMAPS)"
    },
    "username": {
      "type": "string",
      "description": "Login username / email address"
    },
    "password": {
      "type": "string",
      "description": "Login password",
      "writeOnly": true
    },
    "action": {
      "type": "string",
      "enum": [
        "LOGIN",
        "SELECT",
        "EXAMINE",
        "FETCH",
        "SEARCH",
        "LIST",
        "STORE",
        "APPEND",
        "EXPUNGE",
        "NOOP",
        "CAPABILITY",
        "LOGOUT",
        "STATUS"
      ],
      "default": "SELECT",
      "description": "IMAP command to execute"
    },
    "mailbox": {
      "type": "string",
      "default": "INBOX",
      "description": "Mailbox name (for SELECT, EXAMINE, FETCH, SEARCH, STATUS)"
    },
    "messageNumber": {
      "type": "string",
      "description": "Message sequence number or UID (for FETCH, STORE)"
    },
    "fetchItems": {
      "type": "string",
      "default": "BODY[]",
      "description": "FETCH data items (e.g. BODY[], BODY[HEADER], ENVELOPE)"
    },
    "searchCriteria": {
      "type": "string",
      "default": "ALL",
      "description": "IMAP SEARCH criteria (e.g. ALL, UNSEEN, FROM \"user\")"
    },
    "storeFlags": {
      "type": "string",
      "description": "Flags for STORE command (e.g. \\Seen, \\Deleted)"
    },
    "storeAction": {
      "type": "string",
      "default": "+FLAGS",
      "enum": [
        "+FLAGS",
        "-FLAGS",
        "FLAGS"
      ],
      "description": "STORE action (+FLAGS, -FLAGS, FLAGS)"
    },
    "appendMessage": {
      "type": "string",
      "description": "RFC-2822 message content for APPEND command"
    },
    "appendFlags": {
      "type": "string",
      "description": "Optional flags for APPEND (e.g. \\Seen, \\Draft)"
    },
    "startTls": {
      "type": "boolean",
      "default": false,
      "description": "Upgrade plain connection to TLS via STARTTLS command"
    },
    "useSsl": {
      "type": "boolean",
      "default": false,
      "description": "Use IMAPS (SSL/TLS on connect)"
    },
    "trustAll": {
      "type": "boolean",
      "default": false,
      "description": "Trust all SSL certificates"
    },
    "timeout": {
      "type": "integer",
      "minimum": 1,
      "default": 10000,
      "description": "Socket timeout in ms"
    },
    "assertions": {
      "type": "array",
      "description": "Optional step-level assertions (ImapConfigValidator requires type, operator, and expected per item).",
      "items": {
        "$ref": "#/definitions/imapAssertion"
      }
    },
    "extractors": {
      "type": "array",
      "description": "Optional extractors from the IMAP sample result (see ImapConfigValidator).",
      "items": {
        "$ref": "#/definitions/imapExtractor"
      }
    }
  },
  "required": [
    "host"
  ],
  "definitions": {
    "imapAssertion": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "STATUS_CODE",
            "RESPONSE_TIME",
            "BODY_CONTAINS",
            "BODY_EQUALS",
            "BODY_JSON_PATH",
            "BODY_REGEX",
            "NOT_NULL"
          ]
        },
        "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 (required by ImapConfigValidator)"
        },
        "expression": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean"
        }
      },
      "required": [
        "type",
        "operator",
        "expected"
      ]
    },
    "imapExtractor": {
      "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"
            ]
          }
        }
      ]
    }
  }
}
