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

from __future__ import annotations
from .billingcadence import BillingCadence
from .billingperiod import BillingPeriod
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class DtoBillingCycleInfoTypedDict(TypedDict):
    billing_anchor: NotRequired[str]
    r"""billing_anchor is the new billing anchor"""
    billing_cadence: NotRequired[BillingCadence]
    billing_period: NotRequired[BillingPeriod]
    billing_period_count: NotRequired[int]
    r"""billing_period_count is the billing period count"""
    period_end: NotRequired[str]
    r"""period_end is the end of the new billing period"""
    period_start: NotRequired[str]
    r"""period_start is the start of the new billing period"""


class DtoBillingCycleInfo(BaseModel):
    billing_anchor: Optional[str] = None
    r"""billing_anchor is the new billing anchor"""

    billing_cadence: Optional[BillingCadence] = None

    billing_period: Optional[BillingPeriod] = None

    billing_period_count: Optional[int] = None
    r"""billing_period_count is the billing period count"""

    period_end: Optional[str] = None
    r"""period_end is the end of the new billing period"""

    period_start: Optional[str] = None
    r"""period_start is the start of the new billing period"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "billing_anchor",
                "billing_cadence",
                "billing_period",
                "billing_period_count",
                "period_end",
                "period_start",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
