"""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 dub.utils import get_discriminator
from enum import Enum
import pydantic
from pydantic import Discriminator, Tag, model_serializer
from typing import List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, 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"
    DEACTIVATED = "deactivated"
    BANNED = "banned"
    ARCHIVED = "archived"


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 link has generated."""
    conversions: NotRequired[float]
    r"""The number of leads that converted to paying customers."""
    sales: NotRequired[float]
    r"""The total number of sales (includes recurring sales) generated by the short link."""
    sale_amount: NotRequired[float]
    r"""The total dollar value of sales (in cents) generated by the short link."""


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 link has generated."""

    conversions: Optional[float] = 0
    r"""The number of leads that converted to paying customers."""

    sales: Optional[float] = 0
    r"""The total number of sales (includes recurring sales) generated by the short link."""

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["clicks", "leads", "conversions", "sales", "saleAmount"])
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


class BannedReason(str, Enum):
    r"""If the partner was banned from the program, this is the reason for the ban."""

    TOS_VIOLATION = "tos_violation"
    INAPPROPRIATE_CONTENT = "inappropriate_content"
    FAKE_TRAFFIC = "fake_traffic"
    FRAUD = "fraud"
    SPAM = "spam"
    BRAND_ABUSE = "brand_abuse"


class PartnerEnrolledEventFieldsDataReferralFormData8Type(str, Enum):
    PHONE = "phone"


class EightTypedDict(TypedDict):
    key: str
    label: str
    required: bool
    locked: bool
    position: int
    type: PartnerEnrolledEventFieldsDataReferralFormData8Type


class Eight(BaseModel):
    key: str

    label: str

    required: bool

    locked: bool

    position: int

    type: PartnerEnrolledEventFieldsDataReferralFormData8Type


class PartnerEnrolledEventFieldsDataReferralFormData7Type(str, Enum):
    NUMBER = "number"


class SevenTypedDict(TypedDict):
    key: str
    label: str
    required: bool
    locked: bool
    position: int
    type: PartnerEnrolledEventFieldsDataReferralFormData7Type


class Seven(BaseModel):
    key: str

    label: str

    required: bool

    locked: bool

    position: int

    type: PartnerEnrolledEventFieldsDataReferralFormData7Type


class PartnerEnrolledEventFieldsDataReferralFormData6Type(str, Enum):
    MULTI_SELECT = "multiSelect"


class FieldsOptionsTypedDict(TypedDict):
    label: str
    value: str


class FieldsOptions(BaseModel):
    label: str

    value: str


class SixTypedDict(TypedDict):
    key: str
    label: str
    required: bool
    locked: bool
    position: int
    type: PartnerEnrolledEventFieldsDataReferralFormData6Type
    options: List[FieldsOptionsTypedDict]


class Six(BaseModel):
    key: str

    label: str

    required: bool

    locked: bool

    position: int

    type: PartnerEnrolledEventFieldsDataReferralFormData6Type

    options: List[FieldsOptions]


class PartnerEnrolledEventFieldsDataReferralFormData5Type(str, Enum):
    DATE = "date"


class FiveTypedDict(TypedDict):
    key: str
    label: str
    required: bool
    locked: bool
    position: int
    type: PartnerEnrolledEventFieldsDataReferralFormData5Type


class Five(BaseModel):
    key: str

    label: str

    required: bool

    locked: bool

    position: int

    type: PartnerEnrolledEventFieldsDataReferralFormData5Type


class PartnerEnrolledEventFieldsDataReferralFormDataType(str, Enum):
    COUNTRY = "country"


class FourTypedDict(TypedDict):
    key: str
    label: str
    required: bool
    locked: bool
    position: int
    type: PartnerEnrolledEventFieldsDataReferralFormDataType


class Four(BaseModel):
    key: str

    label: str

    required: bool

    locked: bool

    position: int

    type: PartnerEnrolledEventFieldsDataReferralFormDataType


class PartnerEnrolledEventFieldsDataType(str, Enum):
    SELECT = "select"


class OptionsTypedDict(TypedDict):
    label: str
    value: str


class Options(BaseModel):
    label: str

    value: str


class Fields3TypedDict(TypedDict):
    key: str
    label: str
    required: bool
    locked: bool
    position: int
    type: PartnerEnrolledEventFieldsDataType
    options: List[OptionsTypedDict]


class Fields3(BaseModel):
    key: str

    label: str

    required: bool

    locked: bool

    position: int

    type: PartnerEnrolledEventFieldsDataType

    options: List[Options]


class PartnerEnrolledEventFieldsType(str, Enum):
    TEXTAREA = "textarea"


class FieldsConstraintsTypedDict(TypedDict):
    max_length: NotRequired[int]


class FieldsConstraints(BaseModel):
    max_length: Annotated[Optional[int], pydantic.Field(alias="maxLength")] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["maxLength"])
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


class Fields2TypedDict(TypedDict):
    key: str
    label: str
    required: bool
    locked: bool
    position: int
    type: PartnerEnrolledEventFieldsType
    constraints: NotRequired[FieldsConstraintsTypedDict]


class Fields2(BaseModel):
    key: str

    label: str

    required: bool

    locked: bool

    position: int

    type: PartnerEnrolledEventFieldsType

    constraints: Optional[FieldsConstraints] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["constraints"])
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


class FieldsType(str, Enum):
    TEXT = "text"


class ConstraintsTypedDict(TypedDict):
    max_length: NotRequired[int]
    pattern: NotRequired[str]


class Constraints(BaseModel):
    max_length: Annotated[Optional[int], pydantic.Field(alias="maxLength")] = None

    pattern: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["maxLength", "pattern"])
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


class Fields1TypedDict(TypedDict):
    key: str
    label: str
    required: bool
    locked: bool
    position: int
    type: FieldsType
    constraints: NotRequired[ConstraintsTypedDict]


class Fields1(BaseModel):
    key: str

    label: str

    required: bool

    locked: bool

    position: int

    type: FieldsType

    constraints: Optional[Constraints] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["constraints"])
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


FieldsTypedDict = TypeAliasType(
    "FieldsTypedDict",
    Union[
        FourTypedDict,
        FiveTypedDict,
        SevenTypedDict,
        EightTypedDict,
        Fields1TypedDict,
        Fields2TypedDict,
        Fields3TypedDict,
        SixTypedDict,
    ],
)


Fields = Annotated[
    Union[
        Annotated[Fields1, Tag("text")],
        Annotated[Fields2, Tag("textarea")],
        Annotated[Fields3, Tag("select")],
        Annotated[Four, Tag("country")],
        Annotated[Five, Tag("date")],
        Annotated[Six, Tag("multiSelect")],
        Annotated[Seven, Tag("number")],
        Annotated[Eight, Tag("phone")],
    ],
    Discriminator(lambda m: get_discriminator(m, "type", "type")),
]


class ReferralFormDataTypedDict(TypedDict):
    fields: List[FieldsTypedDict]


class ReferralFormData(BaseModel):
    fields: List[Fields]


class PartnerEnrolledEventDataTypedDict(TypedDict):
    id: str
    r"""The partner's unique ID on Dub."""
    name: str
    r"""The partner's full legal name."""
    company_name: Nullable[str]
    r"""If the partner profile type is a company, this is the partner's legal company 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)."""
    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."""
    trusted_at: Nullable[str]
    r"""The date when the partner received the trusted badge in the partner network."""
    program_id: str
    r"""The program's unique ID on Dub."""
    partner_id: str
    r"""The partner'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."""
    created_at: str
    status: Status
    r"""The status of the partner's enrollment in the program."""
    links: Nullable[List[LinksTypedDict]]
    r"""The partner's referral links in this program."""
    description: NotRequired[Nullable[str]]
    r"""A brief description of the partner and their background."""
    group_id: NotRequired[Nullable[str]]
    r"""The partner's group ID on Dub."""
    total_commissions: NotRequired[float]
    r"""The total commissions paid to the partner for their referrals"""
    click_reward_id: NotRequired[Nullable[str]]
    lead_reward_id: NotRequired[Nullable[str]]
    sale_reward_id: NotRequired[Nullable[str]]
    discount_id: NotRequired[Nullable[str]]
    application_id: NotRequired[Nullable[str]]
    r"""If the partner submitted an application to join the program, this is the ID of the application."""
    banned_at: NotRequired[Nullable[str]]
    r"""If the partner was banned from the program, this is the date of the ban."""
    banned_reason: NotRequired[Nullable[BannedReason]]
    r"""If the partner was banned from the program, this is the reason for the ban."""
    referral_form_data: NotRequired[Nullable[ReferralFormDataTypedDict]]
    total_clicks: NotRequired[float]
    r"""The total number of clicks on the partner's links"""
    total_leads: NotRequired[float]
    r"""The total number of leads generated by the partner's links"""
    total_conversions: NotRequired[float]
    r"""The total number of leads that converted to paying customers"""
    total_sales: NotRequired[float]
    r"""The total number of sales generated by the partner's links (includes recurring sales)"""
    total_sale_amount: NotRequired[float]
    r"""Total revenue generated by the partner's links"""
    net_revenue: NotRequired[float]
    r"""Net revenue after commissions (`Total Revenue - Total Commissions`)"""
    earnings_per_click: NotRequired[Nullable[float]]
    r"""Earnings Per Click (EPC) (`Total Revenue ÷ Total Clicks`)"""
    average_lifetime_value: NotRequired[Nullable[float]]
    r"""Average lifetime value for each paying customer (`Total Revenue ÷ Total Conversions`)"""
    click_to_lead_rate: NotRequired[Nullable[float]]
    r"""Percentage of clicks that become leads (`Total Leads ÷ Total Clicks`)"""
    click_to_conversion_rate: NotRequired[Nullable[float]]
    r"""Percentage of clicks that convert to paying customers (`Total Conversions ÷ Total Clicks`)"""
    lead_to_conversion_rate: NotRequired[Nullable[float]]
    r"""Percentage of leads that convert to paying customers (`Total Conversions ÷ Total Leads`)"""
    return_on_ad_spend: NotRequired[Nullable[float]]
    r"""Return On Ad Spend (ROAS) (`Total Revenue ÷ Total Commissions`)"""
    website: NotRequired[Nullable[str]]
    r"""The partner's website URL (including the https protocol)."""
    youtube: NotRequired[Nullable[str]]
    r"""The partner's YouTube channel username (e.g. `johndoe`)."""
    twitter: NotRequired[Nullable[str]]
    r"""The partner's Twitter username (e.g. `johndoe`)."""
    linkedin: NotRequired[Nullable[str]]
    r"""The partner's LinkedIn username (e.g. `johndoe`)."""
    instagram: NotRequired[Nullable[str]]
    r"""The partner's Instagram username (e.g. `johndoe`)."""
    tiktok: NotRequired[Nullable[str]]
    r"""The partner's TikTok username (e.g. `johndoe`)."""


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

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

    company_name: Annotated[Nullable[str], pydantic.Field(alias="companyName")]
    r"""If the partner profile type is a company, this is the partner's legal company 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)."""

    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."""

    trusted_at: Annotated[Nullable[str], pydantic.Field(alias="trustedAt")]
    r"""The date when the partner received the trusted badge in the partner network."""

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

    partner_id: Annotated[str, pydantic.Field(alias="partnerId")]
    r"""The partner'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."""

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

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

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

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

    group_id: Annotated[OptionalNullable[str], pydantic.Field(alias="groupId")] = UNSET
    r"""The partner's group ID on Dub."""

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

    click_reward_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="clickRewardId")
    ] = UNSET

    lead_reward_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="leadRewardId")
    ] = UNSET

    sale_reward_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="saleRewardId")
    ] = UNSET

    discount_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="discountId")
    ] = UNSET

    application_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="applicationId")
    ] = UNSET
    r"""If the partner submitted an application to join the program, this is the ID of the application."""

    banned_at: Annotated[OptionalNullable[str], pydantic.Field(alias="bannedAt")] = (
        UNSET
    )
    r"""If the partner was banned from the program, this is the date of the ban."""

    banned_reason: Annotated[
        OptionalNullable[BannedReason], pydantic.Field(alias="bannedReason")
    ] = UNSET
    r"""If the partner was banned from the program, this is the reason for the ban."""

    referral_form_data: Annotated[
        OptionalNullable[ReferralFormData], pydantic.Field(alias="referralFormData")
    ] = UNSET

    total_clicks: Annotated[Optional[float], pydantic.Field(alias="totalClicks")] = 0
    r"""The total number of clicks on the partner's links"""

    total_leads: Annotated[Optional[float], pydantic.Field(alias="totalLeads")] = 0
    r"""The total number of leads generated by the partner's links"""

    total_conversions: Annotated[
        Optional[float], pydantic.Field(alias="totalConversions")
    ] = 0
    r"""The total number of leads that converted to paying customers"""

    total_sales: Annotated[Optional[float], pydantic.Field(alias="totalSales")] = 0
    r"""The total number of sales generated by the partner's links (includes recurring sales)"""

    total_sale_amount: Annotated[
        Optional[float], pydantic.Field(alias="totalSaleAmount")
    ] = 0
    r"""Total revenue generated by the partner's links"""

    net_revenue: Annotated[Optional[float], pydantic.Field(alias="netRevenue")] = 0
    r"""Net revenue after commissions (`Total Revenue - Total Commissions`)"""

    earnings_per_click: Annotated[
        OptionalNullable[float], pydantic.Field(alias="earningsPerClick")
    ] = UNSET
    r"""Earnings Per Click (EPC) (`Total Revenue ÷ Total Clicks`)"""

    average_lifetime_value: Annotated[
        OptionalNullable[float], pydantic.Field(alias="averageLifetimeValue")
    ] = UNSET
    r"""Average lifetime value for each paying customer (`Total Revenue ÷ Total Conversions`)"""

    click_to_lead_rate: Annotated[
        OptionalNullable[float], pydantic.Field(alias="clickToLeadRate")
    ] = UNSET
    r"""Percentage of clicks that become leads (`Total Leads ÷ Total Clicks`)"""

    click_to_conversion_rate: Annotated[
        OptionalNullable[float], pydantic.Field(alias="clickToConversionRate")
    ] = UNSET
    r"""Percentage of clicks that convert to paying customers (`Total Conversions ÷ Total Clicks`)"""

    lead_to_conversion_rate: Annotated[
        OptionalNullable[float], pydantic.Field(alias="leadToConversionRate")
    ] = UNSET
    r"""Percentage of leads that convert to paying customers (`Total Conversions ÷ Total Leads`)"""

    return_on_ad_spend: Annotated[
        OptionalNullable[float], pydantic.Field(alias="returnOnAdSpend")
    ] = UNSET
    r"""Return On Ad Spend (ROAS) (`Total Revenue ÷ Total Commissions`)"""

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

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

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

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

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "description",
                "groupId",
                "totalCommissions",
                "clickRewardId",
                "leadRewardId",
                "saleRewardId",
                "discountId",
                "applicationId",
                "bannedAt",
                "bannedReason",
                "referralFormData",
                "totalClicks",
                "totalLeads",
                "totalConversions",
                "totalSales",
                "totalSaleAmount",
                "netRevenue",
                "earningsPerClick",
                "averageLifetimeValue",
                "clickToLeadRate",
                "clickToConversionRate",
                "leadToConversionRate",
                "returnOnAdSpend",
                "website",
                "youtube",
                "twitter",
                "linkedin",
                "instagram",
                "tiktok",
            ]
        )
        nullable_fields = set(
            [
                "companyName",
                "email",
                "image",
                "description",
                "country",
                "paypalEmail",
                "stripeConnectId",
                "payoutsEnabledAt",
                "trustedAt",
                "groupId",
                "tenantId",
                "links",
                "clickRewardId",
                "leadRewardId",
                "saleRewardId",
                "discountId",
                "applicationId",
                "bannedAt",
                "bannedReason",
                "referralFormData",
                "earningsPerClick",
                "averageLifetimeValue",
                "clickToLeadRate",
                "clickToConversionRate",
                "leadToConversionRate",
                "returnOnAdSpend",
                "website",
                "youtube",
                "twitter",
                "linkedin",
                "instagram",
                "tiktok",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_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
