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

from __future__ import annotations
from .campaignchanneltype import CampaignChannelType
from .campaignflightworkflow import (
    CampaignFlightWorkflow,
    CampaignFlightWorkflowTypedDict,
)
from .customcpatype import CustomCPAType
from datetime import datetime
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 CampaignWorkflowTypedDict(TypedDict):
    id: Nullable[str]
    name: NotRequired[Nullable[str]]
    description: NotRequired[Nullable[str]]
    start_date: NotRequired[Nullable[datetime]]
    end_date: NotRequired[Nullable[datetime]]
    time_zone: NotRequired[Nullable[str]]
    custom_cpa_click_weight: NotRequired[Nullable[float]]
    custom_cpa_viewthrough_weight: NotRequired[Nullable[float]]
    custom_cpa_type: NotRequired[CustomCPAType]
    impressions_only_budgeting_cpm: NotRequired[Nullable[float]]
    primary_channel: NotRequired[CampaignChannelType]
    primary_goal: NotRequired[Nullable[str]]
    seed_id: NotRequired[Nullable[str]]
    conversion_reporting_columns_count: NotRequired[Nullable[int]]
    flights: NotRequired[Nullable[List[CampaignFlightWorkflowTypedDict]]]


class CampaignWorkflow(BaseModel):
    id: Nullable[str]

    name: OptionalNullable[str] = UNSET

    description: OptionalNullable[str] = UNSET

    start_date: Annotated[
        OptionalNullable[datetime], pydantic.Field(alias="startDate")
    ] = UNSET

    end_date: Annotated[OptionalNullable[datetime], pydantic.Field(alias="endDate")] = (
        UNSET
    )

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

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

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

    custom_cpa_type: Annotated[
        Optional[CustomCPAType], pydantic.Field(alias="customCPAType")
    ] = None

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

    primary_channel: Annotated[
        Optional[CampaignChannelType], pydantic.Field(alias="primaryChannel")
    ] = None

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

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

    conversion_reporting_columns_count: Annotated[
        OptionalNullable[int], pydantic.Field(alias="conversionReportingColumnsCount")
    ] = UNSET

    flights: OptionalNullable[List[CampaignFlightWorkflow]] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "name",
            "description",
            "startDate",
            "endDate",
            "timeZone",
            "customCPAClickWeight",
            "customCPAViewthroughWeight",
            "customCPAType",
            "impressionsOnlyBudgetingCpm",
            "primaryChannel",
            "primaryGoal",
            "seedId",
            "conversionReportingColumnsCount",
            "flights",
        ]
        nullable_fields = [
            "id",
            "name",
            "description",
            "startDate",
            "endDate",
            "timeZone",
            "customCPAClickWeight",
            "customCPAViewthroughWeight",
            "impressionsOnlyBudgetingCpm",
            "primaryGoal",
            "seedId",
            "conversionReportingColumnsCount",
            "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
