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

from __future__ import annotations
from .subscription_subscriptionlineitem import (
    SubscriptionSubscriptionLineItem,
    SubscriptionSubscriptionLineItemTypedDict,
)
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class DtoMatchedSubscriptionLineItemTypedDict(TypedDict):
    end_date: NotRequired[str]
    is_active_for_event: NotRequired[bool]
    price_id: NotRequired[str]
    start_date: NotRequired[str]
    sub_line_item_id: NotRequired[str]
    subscription_id: NotRequired[str]
    subscription_line_item: NotRequired[SubscriptionSubscriptionLineItemTypedDict]
    timestamp_within_range: NotRequired[bool]


class DtoMatchedSubscriptionLineItem(BaseModel):
    end_date: Optional[str] = None

    is_active_for_event: Optional[bool] = None

    price_id: Optional[str] = None

    start_date: Optional[str] = None

    sub_line_item_id: Optional[str] = None

    subscription_id: Optional[str] = None

    subscription_line_item: Optional[SubscriptionSubscriptionLineItem] = None

    timestamp_within_range: Optional[bool] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "end_date",
                "is_active_for_event",
                "price_id",
                "start_date",
                "sub_line_item_id",
                "subscription_id",
                "subscription_line_item",
                "timestamp_within_range",
            ]
        )
        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
