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

from __future__ import annotations
from .dto_billingcycleinfo import DtoBillingCycleInfo, DtoBillingCycleInfoTypedDict
from .dto_invoicepreview import DtoInvoicePreview, DtoInvoicePreviewTypedDict
from .dto_plansummary import DtoPlanSummary, DtoPlanSummaryTypedDict
from .dto_prorationdetails import DtoProrationDetails, DtoProrationDetailsTypedDict
from .subscriptionchangetype import SubscriptionChangeType
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoSubscriptionChangePreviewResponseTypedDict(TypedDict):
    r"""Response showing the financial impact of a subscription plan change"""

    change_type: NotRequired[SubscriptionChangeType]
    current_plan: NotRequired[DtoPlanSummaryTypedDict]
    effective_date: NotRequired[str]
    r"""effective_date is when the change would take effect"""
    metadata: NotRequired[Dict[str, str]]
    r"""metadata from the request"""
    new_billing_cycle: NotRequired[DtoBillingCycleInfoTypedDict]
    next_invoice_preview: NotRequired[DtoInvoicePreviewTypedDict]
    proration_details: NotRequired[DtoProrationDetailsTypedDict]
    subscription_id: NotRequired[str]
    r"""subscription_id is the ID of the subscription being changed"""
    target_plan: NotRequired[DtoPlanSummaryTypedDict]
    warnings: NotRequired[List[str]]
    r"""warnings contains any warnings about the change"""


class DtoSubscriptionChangePreviewResponse(BaseModel):
    r"""Response showing the financial impact of a subscription plan change"""

    change_type: Optional[SubscriptionChangeType] = None

    current_plan: Optional[DtoPlanSummary] = None

    effective_date: Optional[str] = None
    r"""effective_date is when the change would take effect"""

    metadata: Optional[Dict[str, str]] = None
    r"""metadata from the request"""

    new_billing_cycle: Optional[DtoBillingCycleInfo] = None

    next_invoice_preview: Optional[DtoInvoicePreview] = None

    proration_details: Optional[DtoProrationDetails] = None

    subscription_id: Optional[str] = None
    r"""subscription_id is the ID of the subscription being changed"""

    target_plan: Optional[DtoPlanSummary] = None

    warnings: Optional[List[str]] = None
    r"""warnings contains any warnings about the change"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "change_type",
                "current_plan",
                "effective_date",
                "metadata",
                "new_billing_cycle",
                "next_invoice_preview",
                "proration_details",
                "subscription_id",
                "target_plan",
                "warnings",
            ]
        )
        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
