"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from dub.models.components import (
    analyticsbrowsers as components_analyticsbrowsers,
    analyticscities as components_analyticscities,
    analyticscontinents as components_analyticscontinents,
    analyticscount as components_analyticscount,
    analyticscountries as components_analyticscountries,
    analyticsdevices as components_analyticsdevices,
    analyticsos as components_analyticsos,
    analyticsreferers as components_analyticsreferers,
    analyticsrefererurls as components_analyticsrefererurls,
    analyticstimeseries as components_analyticstimeseries,
    analyticstoplinks as components_analyticstoplinks,
    analyticstopurls as components_analyticstopurls,
    analyticstriggers as components_analyticstriggers,
    continentcode as components_continentcode,
    countrycode as components_countrycode,
)
from dub.types import BaseModel
from dub.utils import FieldMetadata, QueryParamMetadata
from enum import Enum
import pydantic
from typing import List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


class Event(str, Enum):
    r"""The type of event to retrieve analytics for. Defaults to `clicks`."""

    CLICKS = "clicks"
    LEADS = "leads"
    SALES = "sales"
    COMPOSITE = "composite"


class QueryParamGroupBy(str, Enum):
    r"""The parameter to group the analytics data points by. Defaults to `count` if undefined. Note that `trigger` is deprecated (use `triggers` instead), but kept for backwards compatibility."""

    COUNT = "count"
    TIMESERIES = "timeseries"
    CONTINENTS = "continents"
    COUNTRIES = "countries"
    CITIES = "cities"
    DEVICES = "devices"
    BROWSERS = "browsers"
    OS = "os"
    TRIGGER = "trigger"
    TRIGGERS = "triggers"
    REFERERS = "referers"
    REFERER_URLS = "referer_urls"
    TOP_LINKS = "top_links"
    TOP_URLS = "top_urls"


class Interval(str, Enum):
    r"""The interval to retrieve analytics for. Takes precedence over start and end. If undefined, defaults to 24h."""

    TWENTY_FOURH = "24h"
    SEVEND = "7d"
    THIRTYD = "30d"
    NINETYD = "90d"
    YTD = "ytd"
    ONEY = "1y"
    ALL = "all"
    ALL_UNFILTERED = "all_unfiltered"


class Trigger(str, Enum):
    r"""The trigger to retrieve analytics for. If undefined, return both QR and link clicks."""

    QR = "qr"
    LINK = "link"


class RetrieveAnalyticsRequestTypedDict(TypedDict):
    event: NotRequired[Event]
    r"""The type of event to retrieve analytics for. Defaults to `clicks`."""
    group_by: NotRequired[QueryParamGroupBy]
    r"""The parameter to group the analytics data points by. Defaults to `count` if undefined. Note that `trigger` is deprecated (use `triggers` instead), but kept for backwards compatibility."""
    domain: NotRequired[str]
    r"""The domain to filter analytics for."""
    key: NotRequired[str]
    r"""The short link slug."""
    link_id: NotRequired[str]
    r"""The unique ID of the short link on Dub."""
    external_id: NotRequired[str]
    r"""This is the ID of the link in the your database. Must be prefixed with 'ext_' when passed as a query parameter."""
    interval: NotRequired[Interval]
    r"""The interval to retrieve analytics for. Takes precedence over start and end. If undefined, defaults to 24h."""
    start: NotRequired[str]
    r"""The start date and time when to retrieve analytics from."""
    end: NotRequired[str]
    r"""The end date and time when to retrieve analytics from. If not provided, defaults to the current date."""
    timezone: NotRequired[str]
    r"""The IANA time zone code for aligning timeseries granularity (e.g. America/New_York). Defaults to UTC."""
    continent: NotRequired[components_continentcode.ContinentCode]
    r"""The continent to retrieve analytics for."""
    country: NotRequired[components_countrycode.CountryCode]
    r"""The country to retrieve analytics for."""
    city: NotRequired[str]
    r"""The city to retrieve analytics for."""
    device: NotRequired[str]
    r"""The device to retrieve analytics for."""
    browser: NotRequired[str]
    r"""The browser to retrieve analytics for."""
    os: NotRequired[str]
    r"""The OS to retrieve analytics for."""
    trigger: NotRequired[Trigger]
    r"""The trigger to retrieve analytics for. If undefined, return both QR and link clicks."""
    referer: NotRequired[str]
    r"""The referer to retrieve analytics for."""
    referer_url: NotRequired[str]
    r"""The full referer URL to retrieve analytics for."""
    url: NotRequired[str]
    r"""The URL to retrieve analytics for."""
    tag_id: NotRequired[str]
    r"""The tag ID to retrieve analytics for."""
    qr: NotRequired[bool]
    r"""Deprecated. Use the `trigger` field instead. Filter for QR code scans. If true, filter for QR codes only. If false, filter for links only. If undefined, return both."""
    root: NotRequired[bool]
    r"""Filter for root domains. If true, filter for domains only. If false, filter for links only. If undefined, return both."""


class RetrieveAnalyticsRequest(BaseModel):
    event: Annotated[
        Optional[Event],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = Event.CLICKS
    r"""The type of event to retrieve analytics for. Defaults to `clicks`."""

    group_by: Annotated[
        Optional[QueryParamGroupBy],
        pydantic.Field(alias="groupBy"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = QueryParamGroupBy.COUNT
    r"""The parameter to group the analytics data points by. Defaults to `count` if undefined. Note that `trigger` is deprecated (use `triggers` instead), but kept for backwards compatibility."""

    domain: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The domain to filter analytics for."""

    key: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The short link slug."""

    link_id: Annotated[
        Optional[str],
        pydantic.Field(alias="linkId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The unique ID of the short link on Dub."""

    external_id: Annotated[
        Optional[str],
        pydantic.Field(alias="externalId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""This is the ID of the link in the your database. Must be prefixed with 'ext_' when passed as a query parameter."""

    interval: Annotated[
        Optional[Interval],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The interval to retrieve analytics for. Takes precedence over start and end. If undefined, defaults to 24h."""

    start: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The start date and time when to retrieve analytics from."""

    end: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The end date and time when to retrieve analytics from. If not provided, defaults to the current date."""

    timezone: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "UTC"
    r"""The IANA time zone code for aligning timeseries granularity (e.g. America/New_York). Defaults to UTC."""

    continent: Annotated[
        Optional[components_continentcode.ContinentCode],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The continent to retrieve analytics for."""

    country: Annotated[
        Optional[components_countrycode.CountryCode],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The country to retrieve analytics for."""

    city: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The city to retrieve analytics for."""

    device: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The device to retrieve analytics for."""

    browser: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The browser to retrieve analytics for."""

    os: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The OS to retrieve analytics for."""

    trigger: Annotated[
        Optional[Trigger],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The trigger to retrieve analytics for. If undefined, return both QR and link clicks."""

    referer: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The referer to retrieve analytics for."""

    referer_url: Annotated[
        Optional[str],
        pydantic.Field(alias="refererUrl"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The full referer URL to retrieve analytics for."""

    url: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The URL to retrieve analytics for."""

    tag_id: Annotated[
        Optional[str],
        pydantic.Field(alias="tagId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The tag ID to retrieve analytics for."""

    qr: Annotated[
        Optional[bool],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Deprecated. Use the `trigger` field instead. Filter for QR code scans. If true, filter for QR codes only. If false, filter for links only. If undefined, return both."""

    root: Annotated[
        Optional[bool],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter for root domains. If true, filter for domains only. If false, filter for links only. If undefined, return both."""


RetrieveAnalyticsResponseBodyTypedDict = Union[
    components_analyticscount.AnalyticsCountTypedDict,
    List[components_analyticstimeseries.AnalyticsTimeseriesTypedDict],
    List[components_analyticscontinents.AnalyticsContinentsTypedDict],
    List[components_analyticscountries.AnalyticsCountriesTypedDict],
    List[components_analyticscities.AnalyticsCitiesTypedDict],
    List[components_analyticsdevices.AnalyticsDevicesTypedDict],
    List[components_analyticsbrowsers.AnalyticsBrowsersTypedDict],
    List[components_analyticsos.AnalyticsOSTypedDict],
    List[components_analyticstriggers.AnalyticsTriggersTypedDict],
    List[components_analyticsreferers.AnalyticsReferersTypedDict],
    List[components_analyticsrefererurls.AnalyticsRefererUrlsTypedDict],
    List[components_analyticstoplinks.AnalyticsTopLinksTypedDict],
    List[components_analyticstopurls.AnalyticsTopUrlsTypedDict],
]
r"""Analytics data"""


RetrieveAnalyticsResponseBody = Union[
    components_analyticscount.AnalyticsCount,
    List[components_analyticstimeseries.AnalyticsTimeseries],
    List[components_analyticscontinents.AnalyticsContinents],
    List[components_analyticscountries.AnalyticsCountries],
    List[components_analyticscities.AnalyticsCities],
    List[components_analyticsdevices.AnalyticsDevices],
    List[components_analyticsbrowsers.AnalyticsBrowsers],
    List[components_analyticsos.AnalyticsOS],
    List[components_analyticstriggers.AnalyticsTriggers],
    List[components_analyticsreferers.AnalyticsReferers],
    List[components_analyticsrefererurls.AnalyticsRefererUrls],
    List[components_analyticstoplinks.AnalyticsTopLinks],
    List[components_analyticstopurls.AnalyticsTopUrls],
]
r"""Analytics data"""
