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

from __future__ import annotations
from dub.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from enum import Enum
import pydantic
from pydantic import model_serializer
from typing_extensions import Annotated, NotRequired, TypedDict


class CreateCustomerRequestBodyTypedDict(TypedDict):
    external_id: str
    r"""Unique identifier for the customer in the client's app."""
    email: NotRequired[Nullable[str]]
    r"""Email of the customer in the client's app."""
    name: NotRequired[Nullable[str]]
    r"""Name of the customer in the client's app. If not provided, a random name will be generated."""
    avatar: NotRequired[Nullable[str]]
    r"""Avatar URL of the customer in the client's app."""


class CreateCustomerRequestBody(BaseModel):
    external_id: Annotated[str, pydantic.Field(alias="externalId")]
    r"""Unique identifier for the customer in the client's app."""

    email: OptionalNullable[str] = UNSET
    r"""Email of the customer in the client's app."""

    name: OptionalNullable[str] = UNSET
    r"""Name of the customer in the client's app. If not provided, a random name will be generated."""

    avatar: OptionalNullable[str] = UNSET
    r"""Avatar URL of the customer in the client's app."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["email", "name", "avatar"]
        nullable_fields = ["email", "name", "avatar"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in 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


class CreateCustomerLinkTypedDict(TypedDict):
    id: str
    r"""The unique ID of the short link."""
    domain: str
    r"""The domain of the short link. If not provided, the primary domain for the workspace will be used (or `dub.sh` if the workspace has no domains)."""
    key: str
    r"""The short link slug. If not provided, a random 7-character slug will be generated."""
    short_link: str
    r"""The full URL of the short link, including the https protocol (e.g. `https://dub.sh/try`)."""
    program_id: Nullable[str]
    r"""The ID of the program the short link is associated with."""


class CreateCustomerLink(BaseModel):
    id: str
    r"""The unique ID of the short link."""

    domain: str
    r"""The domain of the short link. If not provided, the primary domain for the workspace will be used (or `dub.sh` if the workspace has no domains)."""

    key: str
    r"""The short link slug. If not provided, a random 7-character slug will be generated."""

    short_link: Annotated[str, pydantic.Field(alias="shortLink")]
    r"""The full URL of the short link, including the https protocol (e.g. `https://dub.sh/try`)."""

    program_id: Annotated[Nullable[str], pydantic.Field(alias="programId")]
    r"""The ID of the program the short link is associated with."""

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

        serialized = handler(self)

        m = {}

        for n, f in 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


class CreateCustomerPartnerTypedDict(TypedDict):
    id: str
    name: str
    email: str
    image: NotRequired[Nullable[str]]


class CreateCustomerPartner(BaseModel):
    id: str

    name: str

    email: str

    image: OptionalNullable[str] = UNSET

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

        serialized = handler(self)

        m = {}

        for n, f in 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


class CreateCustomerType(str, Enum):
    PERCENTAGE = "percentage"
    FLAT = "flat"


class CreateCustomerInterval(str, Enum):
    MONTH = "month"
    YEAR = "year"


class CreateCustomerDiscountTypedDict(TypedDict):
    id: str
    coupon_id: Nullable[str]
    coupon_test_id: Nullable[str]
    amount: float
    type: CreateCustomerType
    duration: Nullable[float]
    interval: Nullable[CreateCustomerInterval]


class CreateCustomerDiscount(BaseModel):
    id: str

    coupon_id: Annotated[Nullable[str], pydantic.Field(alias="couponId")]

    coupon_test_id: Annotated[Nullable[str], pydantic.Field(alias="couponTestId")]

    amount: float

    type: CreateCustomerType

    duration: Nullable[float]

    interval: Nullable[CreateCustomerInterval]

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = []
        nullable_fields = ["couponId", "couponTestId", "duration", "interval"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in 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


class CreateCustomerResponseBodyTypedDict(TypedDict):
    r"""The customer was created."""

    id: str
    r"""The unique identifier of the customer in Dub."""
    external_id: str
    r"""Unique identifier for the customer in the client's app."""
    name: str
    r"""Name of the customer."""
    created_at: str
    r"""The date the customer was created."""
    email: NotRequired[Nullable[str]]
    r"""Email of the customer."""
    avatar: NotRequired[Nullable[str]]
    r"""Avatar URL of the customer."""
    country: NotRequired[Nullable[str]]
    r"""Country of the customer."""
    link: NotRequired[Nullable[CreateCustomerLinkTypedDict]]
    partner: NotRequired[Nullable[CreateCustomerPartnerTypedDict]]
    discount: NotRequired[Nullable[CreateCustomerDiscountTypedDict]]


class CreateCustomerResponseBody(BaseModel):
    r"""The customer was created."""

    id: str
    r"""The unique identifier of the customer in Dub."""

    external_id: Annotated[str, pydantic.Field(alias="externalId")]
    r"""Unique identifier for the customer in the client's app."""

    name: str
    r"""Name of the customer."""

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]
    r"""The date the customer was created."""

    email: OptionalNullable[str] = UNSET
    r"""Email of the customer."""

    avatar: OptionalNullable[str] = UNSET
    r"""Avatar URL of the customer."""

    country: OptionalNullable[str] = UNSET
    r"""Country of the customer."""

    link: OptionalNullable[CreateCustomerLink] = UNSET

    partner: OptionalNullable[CreateCustomerPartner] = UNSET

    discount: OptionalNullable[CreateCustomerDiscount] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["email", "avatar", "country", "link", "partner", "discount"]
        nullable_fields = ["email", "avatar", "country", "link", "partner", "discount"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in 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
