# coverage: ignore file
from typing import Any, Dict, List, Protocol, Tuple, runtime_checkable

from selenium.webdriver.remote.webelement import WebElement


class SwitchToProtocol(Protocol):  # pragma: no cover
    """Protocol for Selenium switch_to context."""

    def active_element(self) -> WebElement: ...
    def alert(self): ...
    def default_content(self) -> None: ...
    def frame(self, frame_reference) -> None: ...
    def parent_frame(self) -> None: ...
    def window(self, window_name: str) -> None: ...


@runtime_checkable
class SeleniumDriverProtocol(Protocol):  # pragma: no cover
    """
    FULL Selenium WebDriver API — suitable for typing and autocomplete.
    This matches Chrome, Firefox, Edge, Safari WebDriver interfaces.
    """

    # pragma: no cover

    # ----------------------------------------------------------
    # Properties
    # ----------------------------------------------------------
    @property
    def current_url(self) -> str: ...
    @property
    def title(self) -> str: ...
    @property
    def page_source(self) -> str: ...
    @property
    def current_window_handle(self) -> str: ...
    @property
    def window_handles(self) -> List[str]: ...
    @property
    def name(self) -> str: ...  # browser name

    # ----------------------------------------------------------
    # Navigation
    # ----------------------------------------------------------
    def get(self, url: str) -> None: ...
    def back(self) -> None: ...
    def forward(self) -> None: ...
    def refresh(self) -> None: ...

    # ----------------------------------------------------------
    # Window / Browser Controls
    # ----------------------------------------------------------
    def close(self) -> None: ...
    def quit(self) -> None: ...

    def maximize_window(self) -> None: ...
    def minimize_window(self) -> None: ...
    def fullscreen_window(self) -> None: ...

    def set_window_size(self, width: int, height: int) -> None: ...
    def get_window_size(self) -> Dict[str, int]: ...
    def set_window_position(self, x: int, y: int) -> None: ...
    def get_window_position(self) -> Dict[str, int]: ...

    # Tabs / windows
    def switch_to(self) -> SwitchToProtocol: ...

    # ----------------------------------------------------------
    # Element Search
    # ----------------------------------------------------------
    def find_element(self, by: str, value: str) -> WebElement: ...
    def find_elements(self, by: str, value: str) -> List[WebElement]: ...

    # ----------------------------------------------------------
    # JavaScript Execution
    # ----------------------------------------------------------
    def execute_script(self, script: str, *args) -> Any: ...
    def execute_async_script(self, script: str, *args) -> Any: ...

    # ----------------------------------------------------------
    # Cookies API
    # ----------------------------------------------------------
    def get_cookies(self) -> List[Dict[str, Any]]: ...
    def get_cookie(self, name: str) -> Dict[str, Any]: ...
    def add_cookie(self, cookie_dict: Dict[str, Any]) -> None: ...
    def delete_cookie(self, name: str) -> None: ...
    def delete_all_cookies(self) -> None: ...

    # ----------------------------------------------------------
    # Timeouts
    # ----------------------------------------------------------
    def implicitly_wait(self, time_to_wait: float) -> None: ...
    def set_page_load_timeout(self, time_to_wait: float) -> None: ...
    def set_script_timeout(self, time_to_wait: float) -> None: ...

    # ----------------------------------------------------------
    # Logs
    # ----------------------------------------------------------
    def get_log(self, log_type: str) -> List[Dict[str, Any]]: ...
    def log_types(self) -> List[str]: ...

    # ----------------------------------------------------------
    # Actions API (Selenium 4 W3C)
    # ----------------------------------------------------------
    def create_web_element(self, element_id: str) -> WebElement: ...
    def execute(self, command: str, params: Dict[str, Any] = ...) -> Any: ...

    # Mobile (Appium-compatible optional fields)
    def tap(self, positions: List[Tuple[int, int]]) -> None: ...
    def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: int) -> None: ...

    # ----------------------------------------------------------
    # DevTools (Selenium 4)
    # ----------------------------------------------------------
    def execute_cdp_cmd(self, cmd: str, params: Dict[str, Any]) -> Any: ...
    def get_screenshot_as_file(self, filename: str) -> bool: ...
    def get_screenshot_as_png(self) -> bytes: ...
    def get_screenshot_as_base64(self) -> str: ...
