"""WebView discovery module."""

import sys
from nomo_e2e.models import WebViewInfo


class WebViewDiscovery:
    """Discover WebViews running on the system."""

    def find_webviews(self) -> list[WebViewInfo]:
        """Find all WebViews on the system.

        Returns:
            List of discovered WebViews.
        """
        if sys.platform == "darwin":
            from nomo_e2e.discovery.macos import discover_macos_webviews

            return discover_macos_webviews()

        # TODO: Implement other platforms
        return []

    def find_by_bundle_id(self, bundle_id: str) -> list[WebViewInfo]:
        """Find WebViews by bundle ID.

        Args:
            bundle_id: The bundle ID to search for.

        Returns:
            List of matching WebViews.
        """
        return [wv for wv in self.find_webviews() if wv.bundle_id == bundle_id]

    def find_by_name(self, name: str) -> list[WebViewInfo]:
        """Find WebViews by application name.

        Args:
            name: The name to search for.

        Returns:
            List of matching WebViews.
        """
        return [wv for wv in self.find_webviews() if name.lower() in wv.name.lower()]
