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

from __future__ import annotations
from .billingcadence import BillingCadence
from .billingcycle import BillingCycle
from .billingperiod import BillingPeriod
from .prorationbehavior import ProrationBehavior
from .scheduletype import ScheduleType
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoSubscriptionChangeRequestTypedDict(TypedDict):
    r"""Request object for changing a subscription plan (upgrade/downgrade)"""

    billing_cadence: BillingCadence
    billing_cycle: BillingCycle
    billing_period: BillingPeriod
    proration_behavior: ProrationBehavior
    target_plan_id: str
    r"""target_plan_id is the ID of the new plan to change to (required)"""
    billing_period_count: NotRequired[int]
    r"""billing_period_count is the billing period count for the new subscription"""
    change_at: NotRequired[ScheduleType]
    metadata: NotRequired[Dict[str, str]]
    r"""metadata contains additional key-value pairs for storing extra information"""


class DtoSubscriptionChangeRequest(BaseModel):
    r"""Request object for changing a subscription plan (upgrade/downgrade)"""

    billing_cadence: BillingCadence

    billing_cycle: BillingCycle

    billing_period: BillingPeriod

    proration_behavior: ProrationBehavior

    target_plan_id: str
    r"""target_plan_id is the ID of the new plan to change to (required)"""

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

    change_at: Optional[ScheduleType] = None

    metadata: Optional[Dict[str, str]] = None
    r"""metadata contains additional key-value pairs for storing extra information"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["billing_period_count", "change_at", "metadata"])
        serialized = handler(self)
        m = {}

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

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

        return m
