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

from __future__ import annotations
from .cancellationtype import CancellationType
from .dto_invoiceresponse import DtoInvoiceResponse, DtoInvoiceResponseTypedDict
from .dto_prorationdetail import DtoProrationDetail, DtoProrationDetailTypedDict
from .subscriptionstatus import SubscriptionStatus
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoCancelSubscriptionResponseTypedDict(TypedDict):
    cancellation_type: NotRequired[CancellationType]
    effective_date: NotRequired[str]
    message: NotRequired[str]
    r"""Response metadata"""
    processed_at: NotRequired[str]
    proration_details: NotRequired[List[DtoProrationDetailTypedDict]]
    proration_invoice: NotRequired[DtoInvoiceResponseTypedDict]
    reason: NotRequired[str]
    status: NotRequired[SubscriptionStatus]
    subscription_id: NotRequired[str]
    r"""Basic cancellation info"""
    total_credit_amount: NotRequired[str]


class DtoCancelSubscriptionResponse(BaseModel):
    cancellation_type: Optional[CancellationType] = None

    effective_date: Optional[str] = None

    message: Optional[str] = None
    r"""Response metadata"""

    processed_at: Optional[str] = None

    proration_details: Optional[List[DtoProrationDetail]] = None

    proration_invoice: Optional[DtoInvoiceResponse] = None

    reason: Optional[str] = None

    status: Optional[SubscriptionStatus] = None

    subscription_id: Optional[str] = None
    r"""Basic cancellation info"""

    total_credit_amount: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "cancellation_type",
                "effective_date",
                "message",
                "processed_at",
                "proration_details",
                "proration_invoice",
                "reason",
                "status",
                "subscription_id",
                "total_credit_amount",
            ]
        )
        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
