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

from __future__ import annotations
from .attemptpaginatedresult import (
    AttemptPaginatedResult,
    AttemptPaginatedResultTypedDict,
)
from datetime import datetime
from enum import Enum
from outpost_sdk.types import BaseModel, UNSET_SENTINEL
from outpost_sdk.utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import Callable, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


ListTenantDestinationAttemptsEventIDTypedDict = TypeAliasType(
    "ListTenantDestinationAttemptsEventIDTypedDict", Union[str, List[str]]
)
r"""Filter attempts by event ID(s). Use bracket notation for multiple values (e.g., `event_id[0]=e1&event_id[1]=e2`)."""


ListTenantDestinationAttemptsEventID = TypeAliasType(
    "ListTenantDestinationAttemptsEventID", Union[str, List[str]]
)
r"""Filter attempts by event ID(s). Use bracket notation for multiple values (e.g., `event_id[0]=e1&event_id[1]=e2`)."""


class ListTenantDestinationAttemptsStatus(str, Enum):
    r"""Filter attempts by status."""

    SUCCESS = "success"
    FAILED = "failed"


ListTenantDestinationAttemptsTopicTypedDict = TypeAliasType(
    "ListTenantDestinationAttemptsTopicTypedDict", Union[str, List[str]]
)
r"""Filter attempts by event topic(s). Use bracket notation for multiple values (e.g., `topic[0]=user.created&topic[1]=user.updated`)."""


ListTenantDestinationAttemptsTopic = TypeAliasType(
    "ListTenantDestinationAttemptsTopic", Union[str, List[str]]
)
r"""Filter attempts by event topic(s). Use bracket notation for multiple values (e.g., `topic[0]=user.created&topic[1]=user.updated`)."""


ListTenantDestinationAttemptsIncludeTypedDict = TypeAliasType(
    "ListTenantDestinationAttemptsIncludeTypedDict", Union[str, List[str]]
)
r"""Fields to include in the response. Use bracket notation for multiple values (e.g., `include[0]=event&include[1]=response_data`).
- `event`: Include event summary (id, topic, time, eligible_for_retry, metadata)
- `event.data`: Include full event with payload data
- `response_data`: Include response body and headers
- `destination`: Include the full destination object

"""


ListTenantDestinationAttemptsInclude = TypeAliasType(
    "ListTenantDestinationAttemptsInclude", Union[str, List[str]]
)
r"""Fields to include in the response. Use bracket notation for multiple values (e.g., `include[0]=event&include[1]=response_data`).
- `event`: Include event summary (id, topic, time, eligible_for_retry, metadata)
- `event.data`: Include full event with payload data
- `response_data`: Include response body and headers
- `destination`: Include the full destination object

"""


class ListTenantDestinationAttemptsOrderBy(str, Enum):
    r"""Field to sort by."""

    TIME = "time"


class ListTenantDestinationAttemptsDir(str, Enum):
    r"""Sort direction."""

    ASC = "asc"
    DESC = "desc"


class ListTenantDestinationAttemptsRequestTypedDict(TypedDict):
    tenant_id: str
    r"""The ID of the tenant. Required when using AdminApiKey authentication."""
    destination_id: str
    r"""The ID of the destination."""
    event_id: NotRequired[ListTenantDestinationAttemptsEventIDTypedDict]
    r"""Filter attempts by event ID(s). Use bracket notation for multiple values (e.g., `event_id[0]=e1&event_id[1]=e2`)."""
    status: NotRequired[ListTenantDestinationAttemptsStatus]
    r"""Filter attempts by status."""
    topic: NotRequired[ListTenantDestinationAttemptsTopicTypedDict]
    r"""Filter attempts by event topic(s). Use bracket notation for multiple values (e.g., `topic[0]=user.created&topic[1]=user.updated`)."""
    time_gte: NotRequired[datetime]
    r"""Filter attempts by event time >= value (RFC3339 or YYYY-MM-DD format)."""
    time_lte: NotRequired[datetime]
    r"""Filter attempts by event time <= value (RFC3339 or YYYY-MM-DD format)."""
    time_gt: NotRequired[datetime]
    r"""Filter attempts by event time > value (RFC3339 or YYYY-MM-DD format)."""
    time_lt: NotRequired[datetime]
    r"""Filter attempts by event time < value (RFC3339 or YYYY-MM-DD format)."""
    limit: NotRequired[int]
    r"""Number of items per page (default 100, max 1000)."""
    next_cursor: NotRequired[str]
    r"""Cursor for next page of results."""
    prev_cursor: NotRequired[str]
    r"""Cursor for previous page of results."""
    include: NotRequired[ListTenantDestinationAttemptsIncludeTypedDict]
    r"""Fields to include in the response. Use bracket notation for multiple values (e.g., `include[0]=event&include[1]=response_data`).
    - `event`: Include event summary (id, topic, time, eligible_for_retry, metadata)
    - `event.data`: Include full event with payload data
    - `response_data`: Include response body and headers
    - `destination`: Include the full destination object

    """
    order_by: NotRequired[ListTenantDestinationAttemptsOrderBy]
    r"""Field to sort by."""
    direction: NotRequired[ListTenantDestinationAttemptsDir]
    r"""Sort direction."""


class ListTenantDestinationAttemptsRequest(BaseModel):
    tenant_id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""The ID of the tenant. Required when using AdminApiKey authentication."""

    destination_id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""The ID of the destination."""

    event_id: Annotated[
        Optional[ListTenantDestinationAttemptsEventID],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter attempts by event ID(s). Use bracket notation for multiple values (e.g., `event_id[0]=e1&event_id[1]=e2`)."""

    status: Annotated[
        Optional[ListTenantDestinationAttemptsStatus],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter attempts by status."""

    topic: Annotated[
        Optional[ListTenantDestinationAttemptsTopic],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter attempts by event topic(s). Use bracket notation for multiple values (e.g., `topic[0]=user.created&topic[1]=user.updated`)."""

    time_gte: Annotated[
        Optional[datetime],
        pydantic.Field(alias="time[gte]"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter attempts by event time >= value (RFC3339 or YYYY-MM-DD format)."""

    time_lte: Annotated[
        Optional[datetime],
        pydantic.Field(alias="time[lte]"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter attempts by event time <= value (RFC3339 or YYYY-MM-DD format)."""

    time_gt: Annotated[
        Optional[datetime],
        pydantic.Field(alias="time[gt]"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter attempts by event time > value (RFC3339 or YYYY-MM-DD format)."""

    time_lt: Annotated[
        Optional[datetime],
        pydantic.Field(alias="time[lt]"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter attempts by event time < value (RFC3339 or YYYY-MM-DD format)."""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 100
    r"""Number of items per page (default 100, max 1000)."""

    next_cursor: Annotated[
        Optional[str],
        pydantic.Field(alias="next"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Cursor for next page of results."""

    prev_cursor: Annotated[
        Optional[str],
        pydantic.Field(alias="prev"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Cursor for previous page of results."""

    include: Annotated[
        Optional[ListTenantDestinationAttemptsInclude],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Fields to include in the response. Use bracket notation for multiple values (e.g., `include[0]=event&include[1]=response_data`).
    - `event`: Include event summary (id, topic, time, eligible_for_retry, metadata)
    - `event.data`: Include full event with payload data
    - `response_data`: Include response body and headers
    - `destination`: Include the full destination object

    """

    order_by: Annotated[
        Optional[ListTenantDestinationAttemptsOrderBy],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = ListTenantDestinationAttemptsOrderBy.TIME
    r"""Field to sort by."""

    direction: Annotated[
        Optional[ListTenantDestinationAttemptsDir],
        pydantic.Field(alias="dir"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = ListTenantDestinationAttemptsDir.DESC
    r"""Sort direction."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "event_id",
                "status",
                "topic",
                "time[gte]",
                "time[lte]",
                "time[gt]",
                "time[lt]",
                "limit",
                "next_cursor",
                "prev_cursor",
                "include",
                "order_by",
                "direction",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


class ListTenantDestinationAttemptsResponseTypedDict(TypedDict):
    result: AttemptPaginatedResultTypedDict


class ListTenantDestinationAttemptsResponse(BaseModel):
    next: Callable[[], Optional[ListTenantDestinationAttemptsResponse]]

    result: AttemptPaginatedResult
