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

from __future__ import annotations
from openrouter.types import BaseModel, UnrecognizedStr
from openrouter.utils import FieldMetadata, HeaderMetadata, validate_open_enum
import pydantic
from pydantic.functional_validators import PlainValidator
from typing import List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


class GetAnalyticsMetaGlobalsTypedDict(TypedDict):
    http_referer: NotRequired[str]
    r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
    This is used to track API usage per application.

    """
    x_open_router_title: NotRequired[str]
    r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.

    """
    x_open_router_categories: NotRequired[str]
    r"""Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings.

    """


class GetAnalyticsMetaGlobals(BaseModel):
    http_referer: Annotated[
        Optional[str],
        pydantic.Field(alias="HTTP-Referer"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
    This is used to track API usage per application.

    """

    x_open_router_title: Annotated[
        Optional[str],
        pydantic.Field(alias="X-OpenRouter-Title"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.

    """

    x_open_router_categories: Annotated[
        Optional[str],
        pydantic.Field(alias="X-OpenRouter-Categories"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings.

    """


class GetAnalyticsMetaRequestTypedDict(TypedDict):
    http_referer: NotRequired[str]
    r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
    This is used to track API usage per application.

    """
    x_open_router_title: NotRequired[str]
    r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.

    """
    x_open_router_categories: NotRequired[str]
    r"""Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings.

    """


class GetAnalyticsMetaRequest(BaseModel):
    http_referer: Annotated[
        Optional[str],
        pydantic.Field(alias="HTTP-Referer"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
    This is used to track API usage per application.

    """

    x_open_router_title: Annotated[
        Optional[str],
        pydantic.Field(alias="X-OpenRouter-Title"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.

    """

    x_open_router_categories: Annotated[
        Optional[str],
        pydantic.Field(alias="X-OpenRouter-Categories"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings.

    """


class DimensionTypedDict(TypedDict):
    display_label: str
    r"""Human-readable label"""
    name: str
    r"""Dimension identifier used in query requests"""


class Dimension(BaseModel):
    display_label: str
    r"""Human-readable label"""

    name: str
    r"""Dimension identifier used in query requests"""


GranularityName = Union[
    Literal[
        "minute",
        "hour",
        "day",
        "week",
        "month",
    ],
    UnrecognizedStr,
]
r"""Granularity identifier"""


class GranularityTypedDict(TypedDict):
    display_label: str
    r"""Human-readable label"""
    name: GranularityName
    r"""Granularity identifier"""


class Granularity(BaseModel):
    display_label: str
    r"""Human-readable label"""

    name: Annotated[GranularityName, PlainValidator(validate_open_enum(False))]
    r"""Granularity identifier"""


DisplayFormat = Union[
    Literal[
        "number",
        "currency",
        "percent",
        "latency",
        "throughput",
    ],
    UnrecognizedStr,
]
r"""How this metric value should be formatted for display (e.g. percent → multiply by 100 and append %, currency → prefix with $)"""


class MetricTypedDict(TypedDict):
    display_format: DisplayFormat
    r"""How this metric value should be formatted for display (e.g. percent → multiply by 100 and append %, currency → prefix with $)"""
    display_label: str
    r"""Human-readable label"""
    is_rate: bool
    r"""Whether this metric is a rate/ratio (averaged, not summed)"""
    name: str
    r"""Metric identifier used in query requests"""


class Metric(BaseModel):
    display_format: Annotated[DisplayFormat, PlainValidator(validate_open_enum(False))]
    r"""How this metric value should be formatted for display (e.g. percent → multiply by 100 and append %, currency → prefix with $)"""

    display_label: str
    r"""Human-readable label"""

    is_rate: bool
    r"""Whether this metric is a rate/ratio (averaged, not summed)"""

    name: str
    r"""Metric identifier used in query requests"""


OperatorName = Union[
    Literal[
        "eq",
        "neq",
        "in",
        "not_in",
        "gt",
        "gte",
        "lt",
        "lte",
    ],
    UnrecognizedStr,
]
r"""Operator identifier used in filter definitions"""


ValueType = Union[
    Literal[
        "scalar",
        "array",
    ],
    UnrecognizedStr,
]
r"""Whether the operator expects a single value or an array"""


class OperatorTypedDict(TypedDict):
    name: OperatorName
    r"""Operator identifier used in filter definitions"""
    value_type: ValueType
    r"""Whether the operator expects a single value or an array"""


class Operator(BaseModel):
    name: Annotated[OperatorName, PlainValidator(validate_open_enum(False))]
    r"""Operator identifier used in filter definitions"""

    value_type: Annotated[ValueType, PlainValidator(validate_open_enum(False))]
    r"""Whether the operator expects a single value or an array"""


class GetAnalyticsMetaDataTypedDict(TypedDict):
    dimensions: List[DimensionTypedDict]
    granularities: List[GranularityTypedDict]
    metrics: List[MetricTypedDict]
    operators: List[OperatorTypedDict]


class GetAnalyticsMetaData(BaseModel):
    dimensions: List[Dimension]

    granularities: List[Granularity]

    metrics: List[Metric]

    operators: List[Operator]


class GetAnalyticsMetaResponseTypedDict(TypedDict):
    r"""Returns analytics query metadata"""

    data: GetAnalyticsMetaDataTypedDict


class GetAnalyticsMetaResponse(BaseModel):
    r"""Returns analytics query metadata"""

    data: GetAnalyticsMetaData
