"""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 PartnerEnrolledEventEvent(str, Enum):
    PARTNER_ENROLLED = "partner.enrolled"


class Status(str, Enum):
    r"""The status of the partner's enrollment in the program."""

    PENDING = "pending"
    APPROVED = "approved"
    REJECTED = "rejected"
    INVITED = "invited"
    DECLINED = "declined"
    BANNED = "banned"
    ARCHIVED = "archived"


class PartnerEnrolledEventLinkTypedDict(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 PartnerEnrolledEventLink(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 PartnerEnrolledEventDataTypedDict(TypedDict):
    id: str
    r"""The partner's unique ID on Dub."""
    name: str
    r"""The partner's full legal name."""
    email: Nullable[str]
    r"""The partner's email address. Should be a unique value across Dub."""
    image: Nullable[str]
    r"""The partner's avatar image."""
    country: Nullable[str]
    r"""The partner's country (required for tax purposes)."""
    website: Nullable[str]
    r"""The partner's website URL (including the https protocol)."""
    youtube: Nullable[str]
    r"""The partner's YouTube channel username (e.g. `johndoe`)."""
    twitter: Nullable[str]
    r"""The partner's Twitter username (e.g. `johndoe`)."""
    linkedin: Nullable[str]
    r"""The partner's LinkedIn username (e.g. `johndoe`)."""
    instagram: Nullable[str]
    r"""The partner's Instagram username (e.g. `johndoe`)."""
    tiktok: Nullable[str]
    r"""The partner's TikTok username (e.g. `johndoe`)."""
    paypal_email: Nullable[str]
    r"""The partner's PayPal email (for receiving payouts via PayPal)."""
    stripe_connect_id: Nullable[str]
    r"""The partner's Stripe Connect ID (for receiving payouts via Stripe)."""
    payouts_enabled_at: Nullable[str]
    r"""The date when the partner enabled payouts."""
    created_at: str
    r"""The date when the partner was created on Dub."""
    status: Status
    r"""The status of the partner's enrollment in the program."""
    program_id: str
    r"""The program's unique ID on Dub."""
    tenant_id: Nullable[str]
    r"""The partner's unique ID within your database. Can be useful for associating the partner with a user in your database and retrieving/update their data in the future."""
    links: Nullable[List[PartnerEnrolledEventLinkTypedDict]]
    r"""The partner's referral links in this program."""
    description: NotRequired[Nullable[str]]
    r"""A brief description of the partner and their background."""
    clicks: NotRequired[float]
    r"""The total number of clicks on the partner's links."""
    leads: NotRequired[float]
    r"""The total number of leads generated by the partner's links."""
    sales: NotRequired[float]
    r"""The total number of sales generated by the partner's links."""
    sale_amount: NotRequired[float]
    r"""The total amount of sales (in cents) generated by the partner's links."""
    total_commissions: NotRequired[float]
    r"""The total commissions paid to the partner for their referrals."""
    net_revenue: NotRequired[float]
    r"""The total net revenue generated by the partner."""
    earnings: NotRequired[float]
    r"""DEPRECATED: The total earnings/commissions accrued by the partner's links."""


class PartnerEnrolledEventData(BaseModel):
    id: str
    r"""The partner's unique ID on Dub."""

    name: str
    r"""The partner's full legal name."""

    email: Nullable[str]
    r"""The partner's email address. Should be a unique value across Dub."""

    image: Nullable[str]
    r"""The partner's avatar image."""

    country: Nullable[str]
    r"""The partner's country (required for tax purposes)."""

    website: Nullable[str]
    r"""The partner's website URL (including the https protocol)."""

    youtube: Nullable[str]
    r"""The partner's YouTube channel username (e.g. `johndoe`)."""

    twitter: Nullable[str]
    r"""The partner's Twitter username (e.g. `johndoe`)."""

    linkedin: Nullable[str]
    r"""The partner's LinkedIn username (e.g. `johndoe`)."""

    instagram: Nullable[str]
    r"""The partner's Instagram username (e.g. `johndoe`)."""

    tiktok: Nullable[str]
    r"""The partner's TikTok username (e.g. `johndoe`)."""

    paypal_email: Annotated[Nullable[str], pydantic.Field(alias="paypalEmail")]
    r"""The partner's PayPal email (for receiving payouts via PayPal)."""

    stripe_connect_id: Annotated[Nullable[str], pydantic.Field(alias="stripeConnectId")]
    r"""The partner's Stripe Connect ID (for receiving payouts via Stripe)."""

    payouts_enabled_at: Annotated[
        Nullable[str], pydantic.Field(alias="payoutsEnabledAt")
    ]
    r"""The date when the partner enabled payouts."""

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

    status: Status
    r"""The status of the partner's enrollment in the program."""

    program_id: Annotated[str, pydantic.Field(alias="programId")]
    r"""The program's unique ID on Dub."""

    tenant_id: Annotated[Nullable[str], pydantic.Field(alias="tenantId")]
    r"""The partner's unique ID within your database. Can be useful for associating the partner with a user in your database and retrieving/update their data in the future."""

    links: Nullable[List[PartnerEnrolledEventLink]]
    r"""The partner's referral links in this program."""

    description: OptionalNullable[str] = UNSET
    r"""A brief description of the partner and their background."""

    clicks: Optional[float] = 0
    r"""The total number of clicks on the partner's links."""

    leads: Optional[float] = 0
    r"""The total number of leads generated by the partner's links."""

    sales: Optional[float] = 0
    r"""The total number of sales generated by the partner's links."""

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

    total_commissions: Annotated[
        Optional[float], pydantic.Field(alias="totalCommissions")
    ] = 0
    r"""The total commissions paid to the partner for their referrals."""

    net_revenue: Annotated[Optional[float], pydantic.Field(alias="netRevenue")] = 0
    r"""The total net revenue generated by the partner."""

    earnings: Annotated[
        Optional[float],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
        ),
    ] = 0
    r"""DEPRECATED: The total earnings/commissions accrued by the partner's links."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "description",
            "clicks",
            "leads",
            "sales",
            "saleAmount",
            "totalCommissions",
            "netRevenue",
            "earnings",
        ]
        nullable_fields = [
            "email",
            "image",
            "description",
            "country",
            "website",
            "youtube",
            "twitter",
            "linkedin",
            "instagram",
            "tiktok",
            "paypalEmail",
            "stripeConnectId",
            "payoutsEnabledAt",
            "tenantId",
            "links",
        ]
        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


class PartnerEnrolledEventTypedDict(TypedDict):
    r"""Triggered when a partner is enrolled."""

    id: str
    event: PartnerEnrolledEventEvent
    created_at: str
    data: PartnerEnrolledEventDataTypedDict


class PartnerEnrolledEvent(BaseModel):
    r"""Triggered when a partner is enrolled."""

    id: str

    event: PartnerEnrolledEventEvent

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

    data: PartnerEnrolledEventData
