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

from __future__ import annotations
from pydantic import model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class OutboundCampaignCampaignVariablesTypedDict(TypedDict):
    r"""Variables for campaign"""


class OutboundCampaignCampaignVariables(BaseModel):
    r"""Variables for campaign"""


class OutboundCampaignTypedDict(TypedDict):
    campaign_name: str
    r"""Human readable name of campaign"""
    campaign_variables: OutboundCampaignCampaignVariablesTypedDict
    r"""Variables for campaign"""
    daily_start_time: str
    r"""Start time of campaign each day"""
    daily_end_time: str
    r"""End time of campaign each day"""
    timezone: str
    r"""Timezone of campaign"""
    caller_id: Nullable[str]
    r"""Caller ID for call"""
    id: int
    r"""Unique ID for campaign"""
    last_updated_by: str
    r"""Email of user who last updated campaign"""
    source: NotRequired[Nullable[str]]
    r"""Source phone number, email, or SMS number"""
    rate: NotRequired[int]
    r"""Target number of outreach calls per minute"""
    retry_count: NotRequired[int]
    r"""Number of retries per target"""
    retry_interval: NotRequired[Nullable[str]]
    r"""How long to wait before retrying"""
    pause_seconds: NotRequired[Nullable[int]]
    r"""How many seconds to pause between queueing calls. Useful when rate should be less than 1 per minute"""
    created_at: NotRequired[str]
    r"""Timestamp of campaign creation"""
    updated_at: NotRequired[str]
    r"""Timestamp of campaign update"""


class OutboundCampaign(BaseModel):
    campaign_name: str
    r"""Human readable name of campaign"""

    campaign_variables: OutboundCampaignCampaignVariables
    r"""Variables for campaign"""

    daily_start_time: str
    r"""Start time of campaign each day"""

    daily_end_time: str
    r"""End time of campaign each day"""

    timezone: str
    r"""Timezone of campaign"""

    caller_id: Nullable[str]
    r"""Caller ID for call"""

    id: int
    r"""Unique ID for campaign"""

    last_updated_by: str
    r"""Email of user who last updated campaign"""

    source: OptionalNullable[str] = UNSET
    r"""Source phone number, email, or SMS number"""

    rate: Optional[int] = 1
    r"""Target number of outreach calls per minute"""

    retry_count: Optional[int] = 0
    r"""Number of retries per target"""

    retry_interval: OptionalNullable[str] = UNSET
    r"""How long to wait before retrying"""

    pause_seconds: OptionalNullable[int] = UNSET
    r"""How many seconds to pause between queueing calls. Useful when rate should be less than 1 per minute"""

    created_at: Optional[str] = None
    r"""Timestamp of campaign creation"""

    updated_at: Optional[str] = None
    r"""Timestamp of campaign update"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "source",
            "rate",
            "retry_count",
            "retry_interval",
            "pause_seconds",
            "created_at",
            "updated_at",
        ]
        nullable_fields = ["caller_id", "source", "retry_interval", "pause_seconds"]
        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
