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

from __future__ import annotations
from .amount import Amount, AmountTypedDict
from .payment_address import PaymentAddress, PaymentAddressTypedDict
from .session_line_item import SessionLineItem, SessionLineItemTypedDict
from .session_sequence_type import SessionSequenceType
from mollie.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class SessionRequestPaymentTypedDict(TypedDict):
    webhook_url: NotRequired[str]
    r"""The webhook URL where we will send payment status updates to.

    This URL will be automatically set as the webhook URL for all payments created for this session.
    """


class SessionRequestPayment(BaseModel):
    webhook_url: Annotated[Optional[str], pydantic.Field(alias="webhookUrl")] = None
    r"""The webhook URL where we will send payment status updates to.

    This URL will be automatically set as the webhook URL for all payments created for this session.
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["webhookUrl"])
        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 SessionRequestTypedDict(TypedDict):
    amount: AmountTypedDict
    r"""In v2 endpoints, monetary amounts are represented as objects with a `currency` and `value` field."""
    description: str
    r"""A user-friendly description of the session that may be shown to the customer during the checkout process.

    Any payment created for the session will use the same description.
    """
    lines: List[SessionLineItemTypedDict]
    r"""List of items the customer will pay for in this session. The sum of all line items must equal the
    session's amount.

    All lines must have the same currency as the session.
    """
    redirect_url: str
    r"""The URL your customer will be redirected to after the payment process.

    It could make sense for the redirectUrl to contain a unique identifier – like your order ID – so you can show the
    right page referencing the order when your customer returns.
    """
    billing_address: NotRequired[PaymentAddressTypedDict]
    shipping_address: NotRequired[PaymentAddressTypedDict]
    customer_id: NotRequired[str]
    sequence_type: NotRequired[SessionSequenceType]
    metadata: NotRequired[Dict[str, Any]]
    r"""Provide any data you like in a JSON object. We will save the data alongside the entity. Whenever
    you fetch the entity with our API, we will also include the metadata. You can use up to approximately 1kB.

    Any payment created for the session will use the same metadata.
    """
    payment: NotRequired[SessionRequestPaymentTypedDict]
    profile_id: NotRequired[str]
    r"""The identifier referring to the [profile](get-profile) this entity belongs to.

    Most API credentials are linked to a single profile. In these cases the `profileId` can be omitted in the creation
    request. For organization-level credentials such as OAuth access tokens however, the `profileId` parameter is
    required.
    """
    testmode: NotRequired[Nullable[bool]]
    r"""Whether to create the entity in test mode or live mode.

    Most API credentials are specifically created for either live mode or test mode, in which case this parameter must
    not be sent. For organization-level credentials such as OAuth access tokens, you can enable test mode by setting
    `testmode` to `true`.
    """


class SessionRequest(BaseModel):
    amount: Amount
    r"""In v2 endpoints, monetary amounts are represented as objects with a `currency` and `value` field."""

    description: str
    r"""A user-friendly description of the session that may be shown to the customer during the checkout process.

    Any payment created for the session will use the same description.
    """

    lines: List[SessionLineItem]
    r"""List of items the customer will pay for in this session. The sum of all line items must equal the
    session's amount.

    All lines must have the same currency as the session.
    """

    redirect_url: Annotated[str, pydantic.Field(alias="redirectUrl")]
    r"""The URL your customer will be redirected to after the payment process.

    It could make sense for the redirectUrl to contain a unique identifier – like your order ID – so you can show the
    right page referencing the order when your customer returns.
    """

    billing_address: Annotated[
        Optional[PaymentAddress], pydantic.Field(alias="billingAddress")
    ] = None

    shipping_address: Annotated[
        Optional[PaymentAddress], pydantic.Field(alias="shippingAddress")
    ] = None

    customer_id: Annotated[Optional[str], pydantic.Field(alias="customerId")] = None

    sequence_type: Annotated[
        Optional[SessionSequenceType], pydantic.Field(alias="sequenceType")
    ] = None

    metadata: Optional[Dict[str, Any]] = None
    r"""Provide any data you like in a JSON object. We will save the data alongside the entity. Whenever
    you fetch the entity with our API, we will also include the metadata. You can use up to approximately 1kB.

    Any payment created for the session will use the same metadata.
    """

    payment: Optional[SessionRequestPayment] = None

    profile_id: Annotated[Optional[str], pydantic.Field(alias="profileId")] = None
    r"""The identifier referring to the [profile](get-profile) this entity belongs to.

    Most API credentials are linked to a single profile. In these cases the `profileId` can be omitted in the creation
    request. For organization-level credentials such as OAuth access tokens however, the `profileId` parameter is
    required.
    """

    testmode: OptionalNullable[bool] = UNSET
    r"""Whether to create the entity in test mode or live mode.

    Most API credentials are specifically created for either live mode or test mode, in which case this parameter must
    not be sent. For organization-level credentials such as OAuth access tokens, you can enable test mode by setting
    `testmode` to `true`.
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "billingAddress",
                "shippingAddress",
                "customerId",
                "sequenceType",
                "metadata",
                "payment",
                "profileId",
                "testmode",
            ]
        )
        nullable_fields = set(["testmode"])
        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


try:
    SessionRequestPayment.model_rebuild()
except NameError:
    pass
try:
    SessionRequest.model_rebuild()
except NameError:
    pass
