"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: 01c9f6bea15b

from __future__ import annotations
from .currencies import Currencies
from .list_entity_settlement import ListEntitySettlement, ListEntitySettlementTypedDict
from .list_links import ListLinks, ListLinksTypedDict
from mollie import models
from mollie.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from mollie.utils import FieldMetadata, HeaderMetadata, QueryParamMetadata
import pydantic
from pydantic import field_serializer, model_serializer
from typing import Awaitable, Callable, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


class ListSettlementsRequestTypedDict(TypedDict):
    from_: NotRequired[Nullable[str]]
    r"""Provide an ID to start the result set from the item with the given ID and onwards. This allows you to paginate the
    result set.
    """
    limit: NotRequired[Nullable[int]]
    r"""The maximum number of items to return. Defaults to 50 items."""
    balance_id: NotRequired[str]
    r"""Provide the token of the balance to filter the settlements by. This is
    the balance token that the settlement was settled to.
    """
    year: NotRequired[Nullable[str]]
    r"""Provide the year to query the settlements. Must be used combined with `month` parameter"""
    month: NotRequired[Nullable[str]]
    r"""Provide the month to query the settlements. Must be used combined with `year` parameter"""
    currencies: NotRequired[Currencies]
    r"""Provides the currencies to retrieve the settlements. It accepts multiple currencies in a comma-separated format."""
    idempotency_key: NotRequired[str]
    r"""A unique key to ensure idempotent requests. This key should be a UUID v4 string."""


class ListSettlementsRequest(BaseModel):
    from_: Annotated[
        OptionalNullable[str],
        pydantic.Field(alias="from"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Provide an ID to start the result set from the item with the given ID and onwards. This allows you to paginate the
    result set.
    """

    limit: Annotated[
        OptionalNullable[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""The maximum number of items to return. Defaults to 50 items."""

    balance_id: Annotated[
        Optional[str],
        pydantic.Field(alias="balanceId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Provide the token of the balance to filter the settlements by. This is
    the balance token that the settlement was settled to.
    """

    year: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Provide the year to query the settlements. Must be used combined with `month` parameter"""

    month: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Provide the month to query the settlements. Must be used combined with `year` parameter"""

    currencies: Annotated[
        Optional[Currencies],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Provides the currencies to retrieve the settlements. It accepts multiple currencies in a comma-separated format."""

    idempotency_key: Annotated[
        Optional[str],
        pydantic.Field(alias="idempotency-key"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""A unique key to ensure idempotent requests. This key should be a UUID v4 string."""

    @field_serializer("currencies")
    def serialize_currencies(self, value):
        if isinstance(value, str):
            try:
                return models.Currencies(value)
            except ValueError:
                return value
        return value

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "from",
                "limit",
                "balanceId",
                "year",
                "month",
                "currencies",
                "idempotency-key",
            ]
        )
        nullable_fields = set(["from", "limit", "year", "month"])
        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))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m


class ListSettlementsEmbeddedTypedDict(TypedDict):
    settlements: List[ListEntitySettlementTypedDict]
    r"""An array of settlement objects. For a complete reference
    of the settlement object, refer to the [Get settlement endpoint](get-settlement) documentation.
    """


class ListSettlementsEmbedded(BaseModel):
    settlements: List[ListEntitySettlement]
    r"""An array of settlement objects. For a complete reference
    of the settlement object, refer to the [Get settlement endpoint](get-settlement) documentation.
    """


class ListSettlementsResponseBodyTypedDict(TypedDict):
    r"""A list of settlement objects. For a complete reference of the settlement
    object, refer to the [Get settlement endpoint](get-settlement) documentation.
    """

    count: int
    r"""The number of items in this result set. If more items are available, a `_links.next` URL will be present in the result
    as well.

    The maximum number of items per result set is controlled by the `limit` property provided in the request. The default
    limit is 50 items.
    """
    embedded: ListSettlementsEmbeddedTypedDict
    links: ListLinksTypedDict
    r"""Links to help navigate through the lists of items. Every URL object will contain an `href` and a `type` field."""


class ListSettlementsResponseBody(BaseModel):
    r"""A list of settlement objects. For a complete reference of the settlement
    object, refer to the [Get settlement endpoint](get-settlement) documentation.
    """

    count: int
    r"""The number of items in this result set. If more items are available, a `_links.next` URL will be present in the result
    as well.

    The maximum number of items per result set is controlled by the `limit` property provided in the request. The default
    limit is 50 items.
    """

    embedded: Annotated[ListSettlementsEmbedded, pydantic.Field(alias="_embedded")]

    links: Annotated[ListLinks, pydantic.Field(alias="_links")]
    r"""Links to help navigate through the lists of items. Every URL object will contain an `href` and a `type` field."""


class ListSettlementsResponseTypedDict(TypedDict):
    result: ListSettlementsResponseBodyTypedDict


class ListSettlementsResponse(BaseModel):
    next: Union[
        Callable[[], Optional[ListSettlementsResponse]],
        Callable[[], Awaitable[Optional[ListSettlementsResponse]]],
    ]

    result: ListSettlementsResponseBody


try:
    ListSettlementsResponseBody.model_rebuild()
except NameError:
    pass
