"""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, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import Callable, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


ListAttemptsTenantIDTypedDict = TypeAliasType(
    "ListAttemptsTenantIDTypedDict", Union[str, List[str]]
)
r"""Filter attempts by tenant ID(s). Use bracket notation for multiple values (e.g., `tenant_id[0]=t1&tenant_id[1]=t2`).
When authenticated with a Tenant JWT, this parameter is ignored and the JWT's tenant is used.
If not provided with API key auth, returns attempts from all tenants.

"""


ListAttemptsTenantID = TypeAliasType("ListAttemptsTenantID", Union[str, List[str]])
r"""Filter attempts by tenant ID(s). Use bracket notation for multiple values (e.g., `tenant_id[0]=t1&tenant_id[1]=t2`).
When authenticated with a Tenant JWT, this parameter is ignored and the JWT's tenant is used.
If not provided with API key auth, returns attempts from all tenants.

"""


ListAttemptsEventIDTypedDict = TypeAliasType(
    "ListAttemptsEventIDTypedDict", 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`)."""


ListAttemptsEventID = TypeAliasType("ListAttemptsEventID", 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`)."""


DestinationIDTypedDict = TypeAliasType("DestinationIDTypedDict", Union[str, List[str]])
r"""Filter attempts by destination ID(s). Use bracket notation for multiple values (e.g., `destination_id[0]=d1&destination_id[1]=d2`)."""


DestinationID = TypeAliasType("DestinationID", Union[str, List[str]])
r"""Filter attempts by destination ID(s). Use bracket notation for multiple values (e.g., `destination_id[0]=d1&destination_id[1]=d2`)."""


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

    SUCCESS = "success"
    FAILED = "failed"


ListAttemptsTopicTypedDict = TypeAliasType(
    "ListAttemptsTopicTypedDict", 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`)."""


ListAttemptsTopic = TypeAliasType("ListAttemptsTopic", 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`)."""


ListAttemptsIncludeTypedDict = TypeAliasType(
    "ListAttemptsIncludeTypedDict", 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

"""


ListAttemptsInclude = TypeAliasType("ListAttemptsInclude", 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 ListAttemptsOrderBy(str, Enum):
    r"""Field to sort by."""

    TIME = "time"


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

    ASC = "asc"
    DESC = "desc"


class ListAttemptsRequestTypedDict(TypedDict):
    tenant_id: NotRequired[ListAttemptsTenantIDTypedDict]
    r"""Filter attempts by tenant ID(s). Use bracket notation for multiple values (e.g., `tenant_id[0]=t1&tenant_id[1]=t2`).
    When authenticated with a Tenant JWT, this parameter is ignored and the JWT's tenant is used.
    If not provided with API key auth, returns attempts from all tenants.

    """
    event_id: NotRequired[ListAttemptsEventIDTypedDict]
    r"""Filter attempts by event ID(s). Use bracket notation for multiple values (e.g., `event_id[0]=e1&event_id[1]=e2`)."""
    destination_id: NotRequired[DestinationIDTypedDict]
    r"""Filter attempts by destination ID(s). Use bracket notation for multiple values (e.g., `destination_id[0]=d1&destination_id[1]=d2`)."""
    status: NotRequired[ListAttemptsStatus]
    r"""Filter attempts by status."""
    topic: NotRequired[ListAttemptsTopicTypedDict]
    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[ListAttemptsIncludeTypedDict]
    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[ListAttemptsOrderBy]
    r"""Field to sort by."""
    direction: NotRequired[ListAttemptsDir]
    r"""Sort direction."""


class ListAttemptsRequest(BaseModel):
    tenant_id: Annotated[
        Optional[ListAttemptsTenantID],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter attempts by tenant ID(s). Use bracket notation for multiple values (e.g., `tenant_id[0]=t1&tenant_id[1]=t2`).
    When authenticated with a Tenant JWT, this parameter is ignored and the JWT's tenant is used.
    If not provided with API key auth, returns attempts from all tenants.

    """

    event_id: Annotated[
        Optional[ListAttemptsEventID],
        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`)."""

    destination_id: Annotated[
        Optional[DestinationID],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter attempts by destination ID(s). Use bracket notation for multiple values (e.g., `destination_id[0]=d1&destination_id[1]=d2`)."""

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

    topic: Annotated[
        Optional[ListAttemptsTopic],
        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[ListAttemptsInclude],
        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[ListAttemptsOrderBy],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = ListAttemptsOrderBy.TIME
    r"""Field to sort by."""

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "tenant_id",
                "event_id",
                "destination_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 ListAttemptsResponseTypedDict(TypedDict):
    result: AttemptPaginatedResultTypedDict


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

    result: AttemptPaginatedResult
