import typing

import msgspec


class DuckDuckGoMessage(msgspec.Struct):
    created: int
    id: str
    action: str
    model: str
    message: typing.Optional[str] = None
    status: typing.Optional[int] = None
    error_type: typing.Optional[str] = msgspec.field(
        name="type",
        default=None,
    )
    role: typing.Optional[str] = None


class DuckDuckGoImage(msgspec.Struct):
    height: int
    image: str
    image_token: str
    source: str
    thumbnail: str
    thumbnail_token: str
    title: str
    url: str
    width: int


class DuckDuckGoImageResult(msgspec.Struct):
    ads: typing.Optional[typing.Any]
    next: typing.Optional[str]
    query: str
    queryEncoded: str  # noqa: N815
    response_type: str
    results: typing.List[DuckDuckGoImage]


class DuckDuckGoVideoImages(msgspec.Struct):
    large: str
    medium: str
    motion: str
    small: str


class DuckDuckGoStatistics(msgspec.Struct):
    view_count: int = msgspec.field(
        name="views",
        default=0,
    )


class DuckDuckGoVideo(msgspec.Struct):
    content: str
    description: str
    duration: str
    embed_html: str
    embed_url: str
    image_token: str
    images: DuckDuckGoVideoImages
    provider: str
    published: str
    publisher: str
    statistics: DuckDuckGoStatistics
    title: str
    uploader: str


class DuckDuckGoVideoResult(msgspec.Struct):
    ads: typing.Optional[typing.Any]
    next: typing.Optional[str]
    query: str
    queryEncoded: str  # noqa: N815
    response_type: str
    results: typing.List[DuckDuckGoVideo]


class DuckDuckGoTextSearchResult(msgspec.Struct):
    title: str
    href: str
    body: str


class GoogleSearchResult(msgspec.Struct):
    url: str
    title: str
    description: str

    def __repr__(
        self,
    ) -> str:
        return f"SearchResult(url={self.url!r}, title={self.title!r}, description={self.description!r})"


class ThirteenTabsSearchResult(msgspec.Struct):
    link: typing.Optional[
        typing.Union[
            str,
            typing.Tuple[str],
            typing.List[str],
        ]
    ]
    title: typing.Union[
        str,
        typing.Tuple[str],
    ]
    description: typing.Union[
        str,
        typing.Tuple[str],
    ]
    favicon: typing.Optional[
        typing.Union[
            str,
            typing.Tuple[str],
            typing.List[str],
        ]
    ]
    source: typing.Union[
        str,
        typing.Tuple[str],
    ]


class ThirteenTabsImageResult(msgspec.Struct):
    image_url: typing.Optional[str]  # Direct image link
    preview_url: typing.Optional[str]  # Extracted preview URL (if available)
    class_names: typing.List[str]  # CSS classes
    height: typing.Optional[str]  # Image height attribute
    alt_text: str  # Alternative text (if available)


class ThirteenTabsVideoResult(msgspec.Struct):
    title: str
    url: str
    image_url: str
    channel: str
