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

from __future__ import annotations
import pydantic
from pydantic import model_serializer
from ttd_workflows.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing_extensions import Annotated, NotRequired, TypedDict


class CampaignWorkflowROIGoalInputTypedDict(TypedDict):
    maximize_reach: NotRequired[Nullable[bool]]
    maximize_ltv_incremental_reach: NotRequired[Nullable[bool]]
    cpc_in_advertiser_currency: NotRequired[Nullable[float]]
    ctr_in_percent: NotRequired[Nullable[float]]
    nielsen_otp_in_percent: NotRequired[Nullable[float]]
    cpa_in_advertiser_currency: NotRequired[Nullable[float]]
    return_on_ad_spend_percent: NotRequired[Nullable[float]]
    vcr_in_percent: NotRequired[Nullable[float]]
    viewability_in_percent: NotRequired[Nullable[float]]
    vcpm_in_advertiser_currency: NotRequired[Nullable[float]]
    cpcv_in_advertiser_currency: NotRequired[Nullable[float]]
    miaozhen_otp_in_percent: NotRequired[Nullable[float]]


class CampaignWorkflowROIGoalInput(BaseModel):
    maximize_reach: Annotated[
        OptionalNullable[bool], pydantic.Field(alias="maximizeReach")
    ] = UNSET

    maximize_ltv_incremental_reach: Annotated[
        OptionalNullable[bool], pydantic.Field(alias="maximizeLtvIncrementalReach")
    ] = UNSET

    cpc_in_advertiser_currency: Annotated[
        OptionalNullable[float], pydantic.Field(alias="cpcInAdvertiserCurrency")
    ] = UNSET

    ctr_in_percent: Annotated[
        OptionalNullable[float], pydantic.Field(alias="ctrInPercent")
    ] = UNSET

    nielsen_otp_in_percent: Annotated[
        OptionalNullable[float], pydantic.Field(alias="nielsenOTPInPercent")
    ] = UNSET

    cpa_in_advertiser_currency: Annotated[
        OptionalNullable[float], pydantic.Field(alias="cpaInAdvertiserCurrency")
    ] = UNSET

    return_on_ad_spend_percent: Annotated[
        OptionalNullable[float], pydantic.Field(alias="returnOnAdSpendPercent")
    ] = UNSET

    vcr_in_percent: Annotated[
        OptionalNullable[float], pydantic.Field(alias="vcrInPercent")
    ] = UNSET

    viewability_in_percent: Annotated[
        OptionalNullable[float], pydantic.Field(alias="viewabilityInPercent")
    ] = UNSET

    vcpm_in_advertiser_currency: Annotated[
        OptionalNullable[float], pydantic.Field(alias="vcpmInAdvertiserCurrency")
    ] = UNSET

    cpcv_in_advertiser_currency: Annotated[
        OptionalNullable[float], pydantic.Field(alias="cpcvInAdvertiserCurrency")
    ] = UNSET

    miaozhen_otp_in_percent: Annotated[
        OptionalNullable[float], pydantic.Field(alias="miaozhenOTPInPercent")
    ] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "maximizeReach",
            "maximizeLtvIncrementalReach",
            "cpcInAdvertiserCurrency",
            "ctrInPercent",
            "nielsenOTPInPercent",
            "cpaInAdvertiserCurrency",
            "returnOnAdSpendPercent",
            "vcrInPercent",
            "viewabilityInPercent",
            "vcpmInAdvertiserCurrency",
            "cpcvInAdvertiserCurrency",
            "miaozhenOTPInPercent",
        ]
        nullable_fields = [
            "maximizeReach",
            "maximizeLtvIncrementalReach",
            "cpcInAdvertiserCurrency",
            "ctrInPercent",
            "nielsenOTPInPercent",
            "cpaInAdvertiserCurrency",
            "returnOnAdSpendPercent",
            "vcrInPercent",
            "viewabilityInPercent",
            "vcpmInAdvertiserCurrency",
            "cpcvInAdvertiserCurrency",
            "miaozhenOTPInPercent",
        ]
        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
