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

from __future__ import annotations
from .adgroupchannel import AdGroupChannel
from .adgroupfunnellocation import AdGroupFunnelLocation
from .adgroupworkflowassociatebidlistinput import (
    AdGroupWorkflowAssociateBidListInput,
    AdGroupWorkflowAssociateBidListInputTypedDict,
)
from .adgroupworkflowaudiencetargetinginput import (
    AdGroupWorkflowAudienceTargetingInput,
    AdGroupWorkflowAudienceTargetingInputTypedDict,
)
from .adgroupworkflowbudgetinput import (
    AdGroupWorkflowBudgetInput,
    AdGroupWorkflowBudgetInputTypedDict,
)
from .adgroupworkflowroigoalinput import (
    AdGroupWorkflowROIGoalInput,
    AdGroupWorkflowROIGoalInputTypedDict,
)
import pydantic
from pydantic import model_serializer
from ttd_workflows.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class AdGroupCreateWorkflowPrimaryInputTypedDict(TypedDict):
    name: Nullable[str]
    channel: AdGroupChannel
    funnel_location: AdGroupFunnelLocation
    is_enabled: NotRequired[Nullable[bool]]
    description: NotRequired[Nullable[str]]
    budget: NotRequired[AdGroupWorkflowBudgetInputTypedDict]
    base_bid_cpm_in_advertiser_currency: NotRequired[Nullable[float]]
    max_bid_cpm_in_advertiser_currency: NotRequired[Nullable[float]]
    audience_targeting: NotRequired[AdGroupWorkflowAudienceTargetingInputTypedDict]
    roi_goal: NotRequired[AdGroupWorkflowROIGoalInputTypedDict]
    creative_ids: NotRequired[Nullable[List[str]]]
    associated_bid_lists: NotRequired[
        Nullable[List[AdGroupWorkflowAssociateBidListInputTypedDict]]
    ]
    programmatic_guaranteed_private_contract_id: NotRequired[Nullable[str]]


class AdGroupCreateWorkflowPrimaryInput(BaseModel):
    name: Nullable[str]

    channel: AdGroupChannel

    funnel_location: Annotated[
        AdGroupFunnelLocation, pydantic.Field(alias="funnelLocation")
    ]

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

    description: OptionalNullable[str] = UNSET

    budget: Optional[AdGroupWorkflowBudgetInput] = None

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

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

    audience_targeting: Annotated[
        Optional[AdGroupWorkflowAudienceTargetingInput],
        pydantic.Field(alias="audienceTargeting"),
    ] = None

    roi_goal: Annotated[
        Optional[AdGroupWorkflowROIGoalInput], pydantic.Field(alias="roiGoal")
    ] = None

    creative_ids: Annotated[
        OptionalNullable[List[str]], pydantic.Field(alias="creativeIds")
    ] = UNSET

    associated_bid_lists: Annotated[
        OptionalNullable[List[AdGroupWorkflowAssociateBidListInput]],
        pydantic.Field(alias="associatedBidLists"),
    ] = UNSET

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "isEnabled",
            "description",
            "budget",
            "baseBidCPMInAdvertiserCurrency",
            "maxBidCPMInAdvertiserCurrency",
            "audienceTargeting",
            "roiGoal",
            "creativeIds",
            "associatedBidLists",
            "programmaticGuaranteedPrivateContractId",
        ]
        nullable_fields = [
            "isEnabled",
            "description",
            "baseBidCPMInAdvertiserCurrency",
            "maxBidCPMInAdvertiserCurrency",
            "creativeIds",
            "associatedBidLists",
            "name",
            "programmaticGuaranteedPrivateContractId",
        ]
        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
