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

from __future__ import annotations
from .amount import Amount, AmountTypedDict
from .mode import Mode
from .payment_address import PaymentAddress, PaymentAddressTypedDict
from .session_line_item_response import (
    SessionLineItemResponse,
    SessionLineItemResponseTypedDict,
)
from .session_sequence_type_response import SessionSequenceTypeResponse
from .url import URL, URLTypedDict
from enum import Enum
from mollie import models, utils
from mollie.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import field_serializer, model_serializer
from typing import Any, Dict, List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class SessionResponseStatus(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The session's status."""

    OPEN = "open"
    COMPLETED = "completed"
    EXPIRED = "expired"


class SessionResponsePaymentTypedDict(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 SessionResponsePayment(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 SessionResponseLinksTypedDict(TypedDict):
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""

    self_: URLTypedDict
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""


class SessionResponseLinks(BaseModel):
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""

    self_: Annotated[URL, pydantic.Field(alias="self")]
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""


class SessionResponseTypedDict(TypedDict):
    resource: str
    r"""The resource type of the object."""
    id: str
    r"""The identifier uniquely referring to this session. Mollie assigns this identifier at session creation time. Mollie
    will always refer to the session by this ID. Example: `sess_5B8cwPMGnU6qLbRvo7qEZo`.
    """
    mode: Mode
    r"""Whether this entity was created in live mode or in test mode."""
    client_access_token: str
    r"""The client access token for the session. Use the client access token to initialize Mollie Components."""
    status: SessionResponseStatus
    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[SessionLineItemResponseTypedDict]
    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.
    """
    profile_id: 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.
    """
    created_at: str
    r"""The entity's date and time of creation, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."""
    links: SessionResponseLinksTypedDict
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""
    billing_address: NotRequired[PaymentAddressTypedDict]
    shipping_address: NotRequired[PaymentAddressTypedDict]
    customer_id: NotRequired[str]
    sequence_type: NotRequired[SessionSequenceTypeResponse]
    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[SessionResponsePaymentTypedDict]


class SessionResponse(BaseModel):
    resource: str
    r"""The resource type of the object."""

    id: str
    r"""The identifier uniquely referring to this session. Mollie assigns this identifier at session creation time. Mollie
    will always refer to the session by this ID. Example: `sess_5B8cwPMGnU6qLbRvo7qEZo`.
    """

    mode: Mode
    r"""Whether this entity was created in live mode or in test mode."""

    client_access_token: Annotated[str, pydantic.Field(alias="clientAccessToken")]
    r"""The client access token for the session. Use the client access token to initialize Mollie Components."""

    status: SessionResponseStatus

    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[SessionLineItemResponse]
    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.
    """

    profile_id: Annotated[str, pydantic.Field(alias="profileId")]
    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.
    """

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]
    r"""The entity's date and time of creation, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."""

    links: Annotated[SessionResponseLinks, pydantic.Field(alias="_links")]
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""

    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[SessionSequenceTypeResponse], 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[SessionResponsePayment] = None

    @field_serializer("mode")
    def serialize_mode(self, value):
        if isinstance(value, str):
            try:
                return models.Mode(value)
            except ValueError:
                return value
        return value

    @field_serializer("status")
    def serialize_status(self, value):
        if isinstance(value, str):
            try:
                return models.SessionResponseStatus(value)
            except ValueError:
                return value
        return value

    @field_serializer("sequence_type")
    def serialize_sequence_type(self, value):
        if isinstance(value, str):
            try:
                return models.SessionSequenceTypeResponse(value)
            except ValueError:
                return value
        return value

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


try:
    SessionResponsePayment.model_rebuild()
except NameError:
    pass
try:
    SessionResponseLinks.model_rebuild()
except NameError:
    pass
try:
    SessionResponse.model_rebuild()
except NameError:
    pass
