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

from __future__ import annotations
from .adgroupworkflowcomscoresettingsinput import (
    AdGroupWorkflowComscoreSettingsInput,
    AdGroupWorkflowComscoreSettingsInputTypedDict,
)
from .adgroupworkflowcontracttargetinginput import (
    AdGroupWorkflowContractTargetingInput,
    AdGroupWorkflowContractTargetingInputTypedDict,
)
from .adgroupworkflowkoaoptimizationsettingsinput import (
    AdGroupWorkflowKoaOptimizationSettingsInput,
    AdGroupWorkflowKoaOptimizationSettingsInputTypedDict,
)
from .adgroupworkflownewfrequencyconfiginput import (
    AdGroupWorkflowNewFrequencyConfigInput,
    AdGroupWorkflowNewFrequencyConfigInputTypedDict,
)
from .adgroupworkflownielsentrackingattributesinput import (
    AdGroupWorkflowNielsenTrackingAttributesInput,
    AdGroupWorkflowNielsenTrackingAttributesInputTypedDict,
)
from .campaigncreateworkflowadgroupflightinput import (
    CampaignCreateWorkflowAdGroupFlightInput,
    CampaignCreateWorkflowAdGroupFlightInputTypedDict,
)
from .dimensionalbiddingdimensions import DimensionalBiddingDimensions
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 CampaignCreateWorkflowAdGroupAdvancedInputTypedDict(TypedDict):
    koa_optimization_settings: NotRequired[
        AdGroupWorkflowKoaOptimizationSettingsInputTypedDict
    ]
    comscore_settings: NotRequired[AdGroupWorkflowComscoreSettingsInputTypedDict]
    contract_targeting: NotRequired[AdGroupWorkflowContractTargetingInputTypedDict]
    dimensional_bidding_auto_optimization_settings: NotRequired[
        Nullable[List[List[DimensionalBiddingDimensions]]]
    ]
    is_use_clicks_as_conversions_enabled: NotRequired[Nullable[bool]]
    is_use_secondary_conversions_enabled: NotRequired[Nullable[bool]]
    nielsen_tracking_attributes: NotRequired[
        AdGroupWorkflowNielsenTrackingAttributesInputTypedDict
    ]
    new_frequency_configs: NotRequired[
        Nullable[List[AdGroupWorkflowNewFrequencyConfigInputTypedDict]]
    ]
    flights: NotRequired[
        Nullable[List[CampaignCreateWorkflowAdGroupFlightInputTypedDict]]
    ]


class CampaignCreateWorkflowAdGroupAdvancedInput(BaseModel):
    koa_optimization_settings: Annotated[
        Optional[AdGroupWorkflowKoaOptimizationSettingsInput],
        pydantic.Field(alias="koaOptimizationSettings"),
    ] = None

    comscore_settings: Annotated[
        Optional[AdGroupWorkflowComscoreSettingsInput],
        pydantic.Field(alias="comscoreSettings"),
    ] = None

    contract_targeting: Annotated[
        Optional[AdGroupWorkflowContractTargetingInput],
        pydantic.Field(alias="contractTargeting"),
    ] = None

    dimensional_bidding_auto_optimization_settings: Annotated[
        OptionalNullable[List[List[DimensionalBiddingDimensions]]],
        pydantic.Field(alias="dimensionalBiddingAutoOptimizationSettings"),
    ] = UNSET

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

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

    nielsen_tracking_attributes: Annotated[
        Optional[AdGroupWorkflowNielsenTrackingAttributesInput],
        pydantic.Field(alias="nielsenTrackingAttributes"),
    ] = None

    new_frequency_configs: Annotated[
        OptionalNullable[List[AdGroupWorkflowNewFrequencyConfigInput]],
        pydantic.Field(alias="newFrequencyConfigs"),
    ] = UNSET

    flights: OptionalNullable[List[CampaignCreateWorkflowAdGroupFlightInput]] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "koaOptimizationSettings",
            "comscoreSettings",
            "contractTargeting",
            "dimensionalBiddingAutoOptimizationSettings",
            "isUseClicksAsConversionsEnabled",
            "isUseSecondaryConversionsEnabled",
            "nielsenTrackingAttributes",
            "newFrequencyConfigs",
            "flights",
        ]
        nullable_fields = [
            "dimensionalBiddingAutoOptimizationSettings",
            "isUseClicksAsConversionsEnabled",
            "isUseSecondaryConversionsEnabled",
            "newFrequencyConfigs",
            "flights",
        ]
        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
