# generated by datamodel-codegen:
#   filename:  action-configs.json
#   timestamp: 2026-01-25T13:38:24+00:00

from __future__ import annotations

from enum import StrEnum
from typing import Annotated, Any

from aiohttp.web_routedef import view
from black.debug import T
from pydantic import AnyUrl, BaseModel, ConfigDict, Field


class BaseActionConfig(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    image: str | None = None
    """
    Base64 encoded reference image
    """


class ClickType(StrEnum):
    """
    Type of click to perform
    """

    left = 'left'
    right = 'right'


class ClickConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    selector: str = ''
    """
    CSS selector for element to click
    """
    waitTime: int = 1000
    """
    Wait time in milliseconds
    """
    forceClick: bool = False
    """
    Force click even if element not clickable
    """
    scrollIntoView: bool = True
    """
    Scroll element into view before clicking
    """
    waitForElement: bool = True
    """
    Wait for element to be present
    """
    clickType: ClickType = ClickType.left
    """
    Type of click to perform
    """
    clickCount: Annotated[int, Field(ge=1)] = 1
    """
    Number of clicks to perform
    """
    clickAndHold: bool = False
    """
    Whether to click and hold
    """
    holdDuration: int = 1000
    """
    Duration to hold click in milliseconds
    """


class InputConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    selector: str = ''
    """
    CSS selector for input element
    """
    text: str = ''
    """
    Text to input
    """
    clearFirst: bool = True
    """
    Clear field before typing
    """
    waitForElement: bool = True
    """
    Wait for element to be present
    """
    scrollIntoView: bool = True
    """
    Scroll element into view
    """


class NavigateConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    url: str
    """
    URL to navigate to
    """
    waitForLoad: bool = True
    """
    Wait for page to load
    """
    takeScreenshot: bool = False
    """
    Take screenshot after navigation
    """


class WaitType(StrEnum):
    """
    Type of wait to perform
    """

    duration = 'duration'
    element = 'element'
    interactable = 'interactable'


class WaitConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    waitType: WaitType = WaitType.duration
    """
    Type of wait to perform
    """
    duration: int = 3000
    """
    Duration to wait in milliseconds
    """
    selector: str
    """
    CSS selector for element to wait for
    """
    timeout: int = 10000
    """
    Maximum time to wait in milliseconds
    """
    waitForInteractable: bool = False
    """
    Wait for element to be interactable
    """
    fallbackToDuration: bool = True
    """
    Fallback to duration wait if element wait fails
    """
    fallbackDuration: int = 2000
    """
    Duration to wait if fallback triggered
    """


class AssertType(StrEnum):
    """
    Type of assertion
    """

    exists = 'exists'
    visible = 'visible'
    text = 'text'
    value_ = 'value'
    attribute = 'attribute'


class AssertionConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    selector: str
    """
    CSS selector for element
    """
    assertType: AssertType = AssertType.exists
    """
    Type of assertion
    """
    expectedValue: str
    """
    Expected value for assertion
    """
    waitForElement: bool | None = True
    """
    Wait for element to be present
    """
    caseSensitive: bool | None = False
    """
    Case sensitive comparison
    """
    partialMatch: bool | None = False
    """
    Allow partial text matching
    """


class ScreenshotType(StrEnum):
    """
    Type of screenshot to capture
    """

    viewport = 'viewport'
    fullPage = 'fullPage'
    element = 'element'


class Format(StrEnum):
    """
    Output format
    """

    png = 'png'
    jpg = 'jpg'


class ScreenshotConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    screenshotType: ScreenshotType = ScreenshotType.viewport
    """
    Type of screenshot to capture
    """
    selector: str | None = None
    """
    CSS selector for element screenshots
    """
    filename: str | None = 'screenshot.png'
    """
    Output filename
    """
    saveToFile: bool | None = True
    """
    Save screenshot to file system
    """
    includeTimestamp: bool | None = True
    """
    Include timestamp in filename
    """
    format: Format = Format.png
    """
    Output format
    """
    waitForElement: bool | None = True
    """
    Wait for element to be present
    """
    scrollIntoView: bool | None = True
    """
    Scroll element into view
    """
    fullPage: bool | None = False
    """
    Take full page screenshot
    """


class Type(StrEnum):
    """
    Type of form field
    """

    text = 'text'
    password = 'password'
    email = 'email'
    number = 'number'
    tel = 'tel'
    textarea = 'textarea'
    date = 'date'
    time = 'time'
    datetime_local = 'datetime-local'
    checkbox = 'checkbox'
    radio = 'radio'
    select = 'select'
    file = 'file'


class FormFieldOption(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    value: str
    """
    Option value
    """
    label: str
    """
    Option label
    """


class Method(StrEnum):
    """
    HTTP method
    """

    GET = 'GET'
    POST = 'POST'
    PUT = 'PUT'
    DELETE = 'DELETE'
    PATCH = 'PATCH'


class ApiCallConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    method: Method = Method.GET
    """
    HTTP method
    """
    url: str | None = None
    """
    API endpoint URL
    """
    headers: dict[str, str] | None = None
    """
    HTTP headers
    """
    body: str | None = None
    """
    Request body
    """
    outputVariable: str | None = 'apiResponse'
    """
    Variable to store response
    """
    timeout: int | None = 30000
    """
    Request timeout in milliseconds
    """
    retryCount: int | None = 0
    """
    Number of retries
    """
    parseJson: bool | None = True
    """
    Parse response as JSON
    """
    validateStatus: bool | None = True
    """
    Validate HTTP status code
    """
    followRedirects: bool | None = True
    """
    Follow HTTP redirects
    """
    verifySSL: bool | None = True
    """
    Verify SSL certificates
    """
    basicAuthUsername: str | None = None
    """
    Basic auth username
    """
    basicAuthPassword: str | None = None
    """
    Basic auth password
    """


class DatabaseQueryConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    connectionString: str = ''
    """
    Database connection string
    """
    query: str = ''
    """
    SQL query to execute
    """
    outputVariable: str | None = 'queryResult'
    """
    Variable to store result
    """
    logQuery: bool | None = True
    """
    Log the query being executed
    """
    validateConnection: bool = True
    """
    Validate database connection
    """
    timeout: int = 30000
    """
    Query timeout in milliseconds
    """


class DatabaseInsertConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    connectionString: str = ''
    """
    Database connection string
    """
    table: str = ''
    """
    Table name to insert into
    """
    data: dict[str, Any] = Field(default_factory=dict)
    """
    Data to insert (column-value pairs)
    """
    logOperation: bool | None = True
    """
    Log the insert operation
    """
    validateConnection: bool = True
    """
    Validate database connection
    """
    rollbackOnError: bool = True
    """
    Rollback transaction on error
    """


class FileUploadConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    selector: str = ''
    """
    CSS selector for file input
    """
    filePath: str = ''
    """
    Path to file to upload
    """
    waitForElement: bool | None = True
    """
    Wait for element to be present
    """
    scrollIntoView: bool = True
    """
    Scroll element into view
    """
    validateFile: bool | None = True
    """
    Validate file exists before upload
    """


class FileDownloadConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    selector: str = ''
    """
    CSS selector for download link
    """
    downloadPath: str = ''
    """
    Path to save downloaded file
    """
    waitForElement: bool | None = True
    """
    Wait for element to be present
    """
    validateDownload: bool | None = True
    """
    Validate download completed
    """
    overwriteExisting: bool | None = False
    """
    Overwrite existing files
    """


class CustomCodeConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    code: str
    """
    JavaScript code to execute
    """
    outputVariable: str | None = 'customResult'
    """
    Variable to store result
    """
    logExecution: bool | None = True
    """
    Log code execution
    """
    catchErrors: bool | None = True
    """
    Catch and handle errors
    """
    timeout: int = 30000
    """
    Execution timeout in milliseconds
    """


class SubflowConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    flowId: str
    """
    ID of flow to call
    """
    flowName: str | None = None
    """
    Name of flow to call
    """
    inputParameters: list[dict[str, Any]] | None = None
    """
    Input parameters for subflow
    """
    outputParameters: list[dict[str, Any]] | None = None
    """
    Output parameters from subflow
    """
    outputVariable: str | None = 'flowResult'
    """
    Variable to store result
    """
    waitForCompletion: bool | None = True
    """
    Wait for flow to complete
    """
    logExecution: bool | None = True
    """
    Log flow execution
    """
    propagateErrors: bool | None = True
    """
    Propagate errors from subflow
    """


class SendKeysConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    selector: str | None = None
    """
    CSS selector for element to send keys to
    """
    keys: str = ''
    """
    Keys to send
    """
    waitForElement: bool | None = True
    """
    Wait for element to be present
    """
    keyCombinations: list[Any] | None = None
    """
    Optional key combinations payload used by backend actions.
    """


class Direction(StrEnum):
    """
    Scroll direction
    """

    up = 'up'
    down = 'down'
    left = 'left'
    right = 'right'


class ScrollConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    direction: Direction = Direction.down
    """
    Scroll direction
    """
    distance: int | None = 100
    """
    Scroll distance in pixels
    """
    selector: str | None = None
    """
    Element to scroll (optional, defaults to window)
    """


class AssertVisibleConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    selector: str
    """
    CSS selector for element to check
    """
    timeout: int | None = 5000
    """
    Timeout in milliseconds
    """
    waitForElement: bool | None = True
    """
    Wait for element to be present
    """


class ClearInputConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    selector: str
    """
    CSS selector for input element
    """
    scrollIntoView: bool = False
    """
    Scroll element into view before clearing
    """
    maintainFocus: bool = False
    """
    Whether to keep focus on element after clearing
    """
    waitForElement: bool | None = True
    """
    Wait for element to be present
    """


class OpenNewTabConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    url: str
    """
    URL to open in new tab
    """


class SwitchTabConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    tabIndex: Annotated[int | None, Field(ge=0)] = None
    """
    Tab index to switch to
    """
    tabUrl: str | None = None
    """
    URL of tab to switch to (alternative to index)
    """
    switchMethod: str | None = 'auto'
    """
    Explicit switch method (auto/index/url/title)
    """
    tabTitle: str | None = None
    """
    Tab title to switch to (alternative to index)
    """


class GoForwardConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )


class GoBackConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )


class RefreshConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )


class GetPageInfoConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    outputVariable: str | None = 'pageInfo'
    """
    Variable to store page information
    """
    outputKey: str | None = None
    """
    Dot-notation path to extract a specific key from the page info object (e.g. 'title', 'url').
    If omitted, the full page info object is stored.
    """


class JunctionConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    condition: str | None = None
    """
    Condition to evaluate
    """
    truePath: str | None = None
    """
    Path to take if condition is true
    """
    falsePath: str | None = None
    """
    Path to take if condition is false
    """


class ConditionalConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    condition: str
    """
    JavaScript condition to evaluate
    """
    operator: str
    """
    Optional comparison operator used by editor helpers.
    """
    value: Any
    """
    Optional comparison value used by editor helpers.
    """
    thenActions: list[dict[str, Any]] | None = None
    """
    Actions to execute if condition is true
    """
    elseActions: list[dict[str, Any]] | None = None
    """
    Actions to execute if condition is false
    """


class LoopType(StrEnum):
    """
    Type of loop
    """

    count_ = 'count'
    condition = 'condition'
    foreach = 'foreach'


class LoopConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    loopType: LoopType
    """
    Type of loop
    """
    count: Annotated[int, Field(ge=1)]
    """
    Number of iterations (for count loops)
    """
    condition: str
    """
    Condition to continue loop (for condition loops)
    """
    arrayVariable: str | None = None
    """
    Variable containing array to iterate (for foreach loops)
    """
    itemVariable: str | None = 'item'
    """
    Variable name for current item (for foreach loops)
    """
    actions: list[dict[str, Any]] = Field(default_factory=list)
    """
    Actions to execute in each iteration
    """
    maxIterations: Annotated[int | None, Field(ge=1)] = 100
    """
    Maximum iterations to prevent infinite loops
    """


class DragAndDropConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    sourceSelector: str
    """
    CSS selector for element to drag
    """
    targetSelector: str
    """
    CSS selector for drop target
    """
    waitForElement: bool | None = True
    """
    Wait for elements to be present
    """


class CallToFlowConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    flowId: str
    """
    ID of flow to call
    """
    flowName: str | None = None
    """
    Name of flow to call
    """
    outputVariable: str | None = 'flowResult'
    """
    Variable to store result
    """
    inputParameters: list[dict[str, Any]] = Field(default_factory=list)
    """
    Input parameters to pass to subflow
    """
    outputParameters: list[dict[str, Any]] = Field(default_factory=list)
    """
    Output parameters to store result
    """
    propagateErrors: bool = True
    """
    Whether to propagate errors from the subflow
    """
    logExecution: bool = True
    """
    Whether to log execution of the subflow
    """
    waitForCompletion: bool = True
    """
    Wait for subflow to complete
    """
    async_: Annotated[bool, Field(alias='async')] = False
    """
    Execute subflow asynchronously
    """


class SwitchToFrameConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    switchMethod: str | None = 'selector'
    """
    Switch strategy (selector/index/name/id).
    """
    frameSelector: str | None = None
    """
    CSS selector or frame name/ID
    """
    frameIndex: Annotated[int | None, Field(ge=0)] = None
    """
    Frame index (alternative to selector)
    """
    frameName: str | None = None
    """
    Frame name (alternative to selector/index).
    """
    frameId: str | None = None
    """
    Frame id (alternative to selector/index).
    """
    waitForFrame: bool | None = True
    """
    Wait for frame to become available.
    """
    timeout: int | None = 10000
    """
    Wait timeout in milliseconds.
    """
    scrollIntoView: bool | None = True
    """
    Scroll frame into view before switching.
    """


class ExitFrameConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    exitMethod: str | None = 'parent'
    """
    Exit strategy (parent/main/levels).
    """
    levels: Annotated[int | None, Field(ge=1)] = 1
    """
    Number of parent levels when exitMethod is levels.
    """
    returnToMain: bool | None = False
    """
    Force returning to main content after exit.
    """


class SetViewportConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    width: Annotated[int, Field(ge=1)] = 1920
    """
    Viewport width in pixels
    """
    viewportType: str = 'desktop'
    """
    Type of viewport (desktop, mobile, tablet, custom)
    """
    waitAfterResize: int = 1000
    """
    Time to wait after resizing viewport in milliseconds
    """
    screenSizePreset: str = '1080p'
    """
    Optional preset screen size (e.g. 1080p, 720p) for quick configuration
    """
    deviceName: str | None = None
    """Optional device name (e.g. iPhone 12) for device emulation mode
    """
    deviceScaleFactor: int | None = None
    """
    Device scale factor for high DPI emulation (e.g. 3 for iPhone Plus models)
    """
    isMobile: bool | None = None
    """
    Whether to emulate mobile device (affects user agent and viewport behavior)
    """
    hasTouch: bool | None = None
    """
    Whether to emulate touch screen (enables touch events)
    """
    isLandscape: bool | None = None
    """
    Whether to set landscape orientation (swaps width and height)
    """
    userAgent: str | None = None
    """
    Custom user agent string to use in mobile emulation mode
    """
    preserveCookies: bool = False
    """
    Whether to preserve cookies when changing viewport
    """
    preserveLocalStorage: bool = False
    """
    Whether to preserve local storage when changing viewport
    """
    preserveSessionStorage: bool = False
    """
    Whether to preserve session storage when changing viewport
    """
    takeScreenshot: bool = False
    """
    Whether to take screenshot after resizing viewport
    """
    height: Annotated[int, Field(ge=1)] = 1080
    """
    Viewport height in pixels
    """


class Property(StrEnum):
    text = 'text'
    value_ = 'value'
    class_ = 'class'
    id = 'id'
    tagName = 'tagName'
    innerHTML = 'innerHTML'
    outerHTML = 'outerHTML'
    attributes = 'attributes'
    rect = 'rect'
    visible = 'visible'
    enabled = 'enabled'
    selected = 'selected'


class GetElementPropertiesConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    selector: str = ''
    """
    CSS selector for element
    """
    properties: list[Property] = Field(default_factory=list)
    """
    Properties to retrieve
    """
    outputVariable: str | None = 'elementProps'
    """
    Variable to store properties
    """
    waitForElement: bool | None = True
    """
    Wait for element to be present
    """


class Action(StrEnum):
    """
    Action to perform on popup
    """

    accept = 'accept'
    dismiss = 'dismiss'
    text = 'text'


class HandlePopupConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    action: Action = Action.accept
    """
    Action to perform on popup
    """
    text: str | None = None
    """
    Text to enter in prompt popup
    """
    waitForPopup: bool | None = True
    """
    Wait for popup to appear
    """
    timeout: int | None = 5000
    """
    Timeout in milliseconds
    """


class FormField(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    selector: str
    """
    CSS selector to target form field
    """
    value: Any
    """
    Value to fill
    """
    image: str | None = None
    """
    Optional screenshot path
    """
    name: str | None = None
    """
    Human-readable field name
    """
    type: Type = Type.text
    """
    Type of form field
    """
    options: list[FormFieldOption] | None = None
    """
    Options for select/radio fields
    """
    checked: bool | None = False
    """
    Whether checkbox is checked
    """
    multiple: bool = False
    """
    Whether select allows multiple selections
    """


class FormFillConfig(BaseActionConfig):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    fields: list[FormField] = Field(default_factory=list)
    """
    Array of form field configurations
    """
    waitForElements: bool = True
    """
    Wait for all form elements to be present
    """
    clearFirst: bool = True
    """
    Clear existing values before filling
    """
    submitAfterFill: bool = False
    """
    Automatically submit form after filling
    """
    smartFieldDetection: bool = True
    """
    Automatically detect field types
    """


class ActionConfigurations(BaseModel):
    """
    Configuration schemas for all automation actions
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    actionConfigs: (
        dict[
            str,
            ClickConfig
            | InputConfig
            | SendKeysConfig
            | WaitConfig
            | NavigateConfig
            | ScrollConfig
            | ScreenshotConfig
            | AssertionConfig
            | AssertVisibleConfig
            | FormFillConfig
            | ClearInputConfig
            | OpenNewTabConfig
            | SwitchTabConfig
            | GoForwardConfig
            | GoBackConfig
            | RefreshConfig
            | GetPageInfoConfig
            | JunctionConfig
            | ApiCallConfig
            | ConditionalConfig
            | LoopConfig
            | DatabaseQueryConfig
            | DatabaseInsertConfig
            | CustomCodeConfig
            | DragAndDropConfig
            | CallToFlowConfig
            | SwitchToFrameConfig
            | ExitFrameConfig
            | SetViewportConfig
            | GetElementPropertiesConfig
            | HandlePopupConfig
            | FileUploadConfig
            | FileDownloadConfig
            | SubflowConfig,
        ]
        | None
    ) = None
