"""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 import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class PartnerCreatedEventEvent(str, Enum):
    PARTNER_CREATED = "partner.created"


class Status(str, Enum):
    APPROVED = "approved"
    PENDING = "pending"
    REJECTED = "rejected"


class LinksTypedDict(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`)."""
    url: str
    r"""The destination URL of the short link."""
    clicks: NotRequired[float]
    r"""The number of clicks on the short link."""
    leads: NotRequired[float]
    r"""The number of leads the short links has generated."""
    sales: NotRequired[float]
    r"""The number of sales the short links has generated."""
    sale_amount: NotRequired[float]
    r"""The total dollar amount of sales the short links has generated (in cents)."""


class Links(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`)."""

    url: str
    r"""The destination URL of the short link."""

    clicks: Optional[float] = 0
    r"""The number of clicks on the short link."""

    leads: Optional[float] = 0
    r"""The number of leads the short links has generated."""

    sales: Optional[float] = 0
    r"""The number of sales the short links has generated."""

    sale_amount: Annotated[Optional[float], pydantic.Field(alias="saleAmount")] = 0
    r"""The total dollar amount of sales the short links has generated (in cents)."""


class PartnerCreatedEventDataTypedDict(TypedDict):
    id: str
    name: str
    email: Nullable[str]
    image: Nullable[str]
    country: Nullable[str]
    payouts_enabled: bool
    created_at: str
    status: Status
    program_id: str
    tenant_id: Nullable[str]
    links: Nullable[List[LinksTypedDict]]
    description: NotRequired[Nullable[str]]
    clicks: NotRequired[float]
    leads: NotRequired[float]
    sales: NotRequired[float]
    sale_amount: NotRequired[float]
    earnings: NotRequired[float]


class PartnerCreatedEventData(BaseModel):
    id: str

    name: str

    email: Nullable[str]

    image: Nullable[str]

    country: Nullable[str]

    payouts_enabled: Annotated[bool, pydantic.Field(alias="payoutsEnabled")]

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]

    status: Status

    program_id: Annotated[str, pydantic.Field(alias="programId")]

    tenant_id: Annotated[Nullable[str], pydantic.Field(alias="tenantId")]

    links: Nullable[List[Links]]

    description: OptionalNullable[str] = UNSET

    clicks: Optional[float] = 0

    leads: Optional[float] = 0

    sales: Optional[float] = 0

    sale_amount: Annotated[Optional[float], pydantic.Field(alias="saleAmount")] = 0

    earnings: Optional[float] = 0

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "description",
            "clicks",
            "leads",
            "sales",
            "saleAmount",
            "earnings",
        ]
        nullable_fields = [
            "email",
            "image",
            "country",
            "tenantId",
            "links",
            "description",
        ]
        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 PartnerCreatedEventTypedDict(TypedDict):
    r"""Triggered when a partner is created."""

    id: str
    event: PartnerCreatedEventEvent
    created_at: str
    data: PartnerCreatedEventDataTypedDict


class PartnerCreatedEvent(BaseModel):
    r"""Triggered when a partner is created."""

    id: str

    event: PartnerCreatedEventEvent

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]

    data: PartnerCreatedEventData
