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

from __future__ import annotations
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class DtoOverrideEntitlementRequestTypedDict(TypedDict):
    entitlement_id: str
    r"""EntitlementID references the plan/addon entitlement to override"""
    is_enabled: NotRequired[bool]
    r"""IsEnabled determines if the entitlement is enabled or disabled"""
    static_value: NotRequired[str]
    r"""StaticValue is the static value for static features"""
    usage_limit: NotRequired[int]
    r"""UsageLimit is the new usage limit (only these 3 fields can be overridden)
    For metered features, nil means unlimited usage
    """


class DtoOverrideEntitlementRequest(BaseModel):
    entitlement_id: str
    r"""EntitlementID references the plan/addon entitlement to override"""

    is_enabled: Optional[bool] = None
    r"""IsEnabled determines if the entitlement is enabled or disabled"""

    static_value: Optional[str] = None
    r"""StaticValue is the static value for static features"""

    usage_limit: Optional[int] = None
    r"""UsageLimit is the new usage limit (only these 3 fields can be overridden)
    For metered features, nil means unlimited usage
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["is_enabled", "static_value", "usage_limit"])
        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
