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

from __future__ import annotations
from polar_sdk.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from pydantic import model_serializer
from typing_extensions import NotRequired, TypedDict


class CustomerSessionCustomerExternalIDCreateTypedDict(TypedDict):
    r"""Schema for creating a customer session using an external customer ID."""

    external_customer_id: str
    r"""External ID of the customer to create a session for."""
    member_id: NotRequired[Nullable[str]]
    r"""ID of the member to create a session for. When not provided and the organization has `member_model_enabled`, the owner member of the customer will be used for individual customers."""
    external_member_id: NotRequired[Nullable[str]]
    r"""External ID of the member to create a session for. Alternative to `member_id`."""
    return_url: NotRequired[Nullable[str]]
    r"""When set, a back button will be shown in the customer portal to return to this URL."""


class CustomerSessionCustomerExternalIDCreate(BaseModel):
    r"""Schema for creating a customer session using an external customer ID."""

    external_customer_id: str
    r"""External ID of the customer to create a session for."""

    member_id: OptionalNullable[str] = UNSET
    r"""ID of the member to create a session for. When not provided and the organization has `member_model_enabled`, the owner member of the customer will be used for individual customers."""

    external_member_id: OptionalNullable[str] = UNSET
    r"""External ID of the member to create a session for. Alternative to `member_id`."""

    return_url: OptionalNullable[str] = UNSET
    r"""When set, a back button will be shown in the customer portal to return to this URL."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["member_id", "external_member_id", "return_url"]
        nullable_fields = ["member_id", "external_member_id", "return_url"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

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

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
