{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.anguskit.com/schema/angusmeter/plugins/angus-appium.json",
  "type": "object",
  "properties": {
    "action": {
      "type": "string",
      "enum": [
        "TAP",
        "DOUBLE_TAP",
        "LONG_PRESS",
        "SEND_KEYS",
        "CLEAR",
        "SWIPE",
        "SCROLL",
        "PINCH",
        "ZOOM",
        "SCREENSHOT",
        "WAIT_FOR_ELEMENT",
        "ASSERT",
        "GET_TEXT",
        "GET_ATTRIBUTE",
        "PRESS_BACK",
        "LAUNCH_APP",
        "CLOSE_APP",
        "HIDE_KEYBOARD",
        "CONTEXT_SWITCH",
        "DEEP_LINK",
        "SET_ORIENTATION",
        "BACKGROUND",
        "OPEN_NOTIFICATION"
      ],
      "description": "The mobile action to perform"
    },
    "locator": {
      "type": "string",
      "description": "Locator expression for the target element"
    },
    "locatorStrategy": {
      "type": "string",
      "enum": [
        "ID",
        "XPATH",
        "ACCESSIBILITY_ID",
        "CLASS_NAME",
        "ANDROID_UI_AUTOMATOR",
        "IOS_NS_PREDICATE_STRING",
        "IOS_CLASS_CHAIN"
      ],
      "description": "Strategy used to locate the element"
    },
    "value": {
      "type": "string",
      "description": "Value to send for SEND_KEYS or other value-based actions"
    },
    "appiumServerUrl": {
      "type": "string",
      "format": "uri",
      "default": "http://127.0.0.1:4723",
      "description": "Appium server URL"
    },
    "platformName": {
      "type": "string",
      "enum": [
        "Android",
        "iOS"
      ],
      "description": "Target mobile platform"
    },
    "deviceName": {
      "type": "string",
      "description": "Name of the device or emulator"
    },
    "app": {
      "type": "string",
      "description": "Path or URL to the application package (.apk / .ipa)"
    },
    "automationName": {
      "type": "string",
      "enum": [
        "UiAutomator2",
        "XCUITest",
        "Espresso"
      ],
      "description": "Appium automation engine"
    },
    "assertType": {
      "type": "string",
      "enum": [
        "ELEMENT_VISIBLE",
        "ELEMENT_TEXT",
        "ELEMENT_ENABLED",
        "ELEMENT_SELECTED",
        "ELEMENT_ATTRIBUTE",
        "ELEMENT_COUNT",
        "CURRENT_ACTIVITY",
        "CURRENT_PACKAGE",
        "KEYBOARD_SHOWN",
        "ORIENTATION"
      ],
      "description": "Assertion type for ASSERT action"
    },
    "expected": {
      "type": "string",
      "description": "Expected value for ASSERT comparisons"
    },
    "attribute": {
      "type": "string",
      "description": "Attribute name for GET_ATTRIBUTE or ELEMENT_ATTRIBUTE assert"
    },
    "direction": {
      "type": "string",
      "enum": [
        "up",
        "down",
        "left",
        "right"
      ],
      "description": "Swipe or scroll direction"
    },
    "duration": {
      "type": "integer",
      "default": 1000,
      "description": "Duration in milliseconds for gestures or background"
    },
    "timeout": {
      "type": "integer",
      "default": 10000,
      "description": "Action timeout in milliseconds"
    },
    "appId": {
      "type": "string",
      "description": "Application package/bundle ID for LAUNCH_APP and CLOSE_APP"
    },
    "deepLinkUrl": {
      "type": "string",
      "description": "Deep link URL for DEEP_LINK action"
    },
    "orientation": {
      "type": "string",
      "enum": [
        "portrait",
        "landscape"
      ],
      "description": "Device orientation for SET_ORIENTATION"
    },
    "contextName": {
      "type": "string",
      "description": "Context name for CONTEXT_SWITCH (e.g. NATIVE_APP, WEBVIEW_xxx, or 'auto')"
    },
    "startX": {
      "type": "integer",
      "description": "Start X percent for SWIPE (0-100)"
    },
    "startY": {
      "type": "integer",
      "description": "Start Y percent for SWIPE (0-100)"
    },
    "endX": {
      "type": "integer",
      "description": "End X percent for SWIPE (0-100)"
    },
    "endY": {
      "type": "integer",
      "description": "End Y percent for SWIPE (0-100)"
    },
    "assertions": {
      "type": "array",
      "description": "Optional step-level assertions evaluated by AssertionEngine against the mobile step SampleResult (see AppiumSampler).",
      "items": {
        "$ref": "#/definitions/appiumAssertion"
      }
    },
    "extractors": {
      "type": "array",
      "description": "Optional extractors from the step response body (JSON) into variables.",
      "items": {
        "$ref": "#/definitions/appiumExtractor"
      }
    }
  },
  "required": [
    "action"
  ],
  "definitions": {
    "appiumAssertion": {
      "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",
            "METRIC_SCORE",
            "TOKEN_COUNT",
            "API_COST",
            "LLM_LATENCY",
            "JSON_SCHEMA",
            "NO_PII",
            "RESPONSE_BODY",
            "URL",
            "TITLE",
            "ELEMENT_TEXT",
            "ELEMENT_VALUE",
            "ELEMENT_VISIBLE",
            "ORIENTATION"
          ]
        },
        "operator": {
          "type": "string"
        },
        "expected": {
          "description": "Expected value for the assertion"
        },
        "expression": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean"
        }
      },
      "required": [
        "type"
      ]
    },
    "appiumExtractor": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "JSON_PATH",
            "XPATH",
            "REGEX",
            "HEADER",
            "COOKIE",
            "RESPONSE_CODE",
            "RESPONSE_TIME"
          ]
        },
        "expression": {
          "type": "string"
        },
        "variable": {
          "type": "string"
        },
        "defaultValue": {
          "type": "string"
        }
      },
      "required": [
        "type",
        "variable"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "JSON_PATH",
                  "XPATH",
                  "REGEX",
                  "HEADER",
                  "COOKIE"
                ]
              }
            }
          },
          "then": {
            "required": [
              "expression"
            ]
          }
        }
      ]
    }
  }
}
