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

from __future__ import annotations
from .dto_featureresponse import DtoFeatureResponse, DtoFeatureResponseTypedDict
from .entitlemententitytype import EntitlementEntityType
from .entitlementusageresetperiod import EntitlementUsageResetPeriod
from .featuretype import FeatureType
from .status import Status
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional, TYPE_CHECKING
from typing_extensions import NotRequired, TypedDict

if TYPE_CHECKING:
    from .dto_addonresponse import DtoAddonResponse, DtoAddonResponseTypedDict
    from .dto_planresponse import DtoPlanResponse, DtoPlanResponseTypedDict


class DtoEntitlementResponseTypedDict(TypedDict):
    addon: NotRequired["DtoAddonResponseTypedDict"]
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    display_order: NotRequired[int]
    end_date: NotRequired[str]
    entity_id: NotRequired[str]
    entity_type: NotRequired[EntitlementEntityType]
    environment_id: NotRequired[str]
    feature: NotRequired[DtoFeatureResponseTypedDict]
    feature_id: NotRequired[str]
    feature_type: NotRequired[FeatureType]
    id: NotRequired[str]
    is_enabled: NotRequired[bool]
    is_soft_limit: NotRequired[bool]
    parent_entitlement_id: NotRequired[str]
    plan: NotRequired["DtoPlanResponseTypedDict"]
    plan_id: NotRequired[str]
    r"""TODO: Remove this once we have a proper entitlement entity type"""
    start_date: NotRequired[str]
    static_value: NotRequired[str]
    status: NotRequired[Status]
    tenant_id: NotRequired[str]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]
    usage_limit: NotRequired[int]
    usage_reset_period: NotRequired[EntitlementUsageResetPeriod]


class DtoEntitlementResponse(BaseModel):
    addon: Optional["DtoAddonResponse"] = None

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    display_order: Optional[int] = None

    end_date: Optional[str] = None

    entity_id: Optional[str] = None

    entity_type: Optional[EntitlementEntityType] = None

    environment_id: Optional[str] = None

    feature: Optional[DtoFeatureResponse] = None

    feature_id: Optional[str] = None

    feature_type: Optional[FeatureType] = None

    id: Optional[str] = None

    is_enabled: Optional[bool] = None

    is_soft_limit: Optional[bool] = None

    parent_entitlement_id: Optional[str] = None

    plan: Optional["DtoPlanResponse"] = None

    plan_id: Optional[str] = None
    r"""TODO: Remove this once we have a proper entitlement entity type"""

    start_date: Optional[str] = None

    static_value: Optional[str] = None

    status: Optional[Status] = None

    tenant_id: Optional[str] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    usage_limit: Optional[int] = None

    usage_reset_period: Optional[EntitlementUsageResetPeriod] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "addon",
                "created_at",
                "created_by",
                "display_order",
                "end_date",
                "entity_id",
                "entity_type",
                "environment_id",
                "feature",
                "feature_id",
                "feature_type",
                "id",
                "is_enabled",
                "is_soft_limit",
                "parent_entitlement_id",
                "plan",
                "plan_id",
                "start_date",
                "static_value",
                "status",
                "tenant_id",
                "updated_at",
                "updated_by",
                "usage_limit",
                "usage_reset_period",
            ]
        )
        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
