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

from __future__ import annotations
from .dto_creditgrantresponse import (
    DtoCreditGrantResponse,
    DtoCreditGrantResponseTypedDict,
)
from .types_status import TypesStatus
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional, TYPE_CHECKING
from typing_extensions import NotRequired, TypedDict

if TYPE_CHECKING:
    from .dto_entitlementresponse import (
        DtoEntitlementResponse,
        DtoEntitlementResponseTypedDict,
    )
    from .dto_priceresponse import DtoPriceResponse, DtoPriceResponseTypedDict


class DtoPlanResponseTypedDict(TypedDict):
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    credit_grants: NotRequired[List[DtoCreditGrantResponseTypedDict]]
    description: NotRequired[str]
    display_order: NotRequired[int]
    entitlements: NotRequired[List["DtoEntitlementResponseTypedDict"]]
    environment_id: NotRequired[str]
    id: NotRequired[str]
    lookup_key: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    name: NotRequired[str]
    prices: NotRequired[List["DtoPriceResponseTypedDict"]]
    r"""TODO: Add inline addons"""
    status: NotRequired[TypesStatus]
    tenant_id: NotRequired[str]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


class DtoPlanResponse(BaseModel):
    created_at: Optional[str] = None

    created_by: Optional[str] = None

    credit_grants: Optional[List[DtoCreditGrantResponse]] = None

    description: Optional[str] = None

    display_order: Optional[int] = None

    entitlements: Optional[List["DtoEntitlementResponse"]] = None

    environment_id: Optional[str] = None

    id: Optional[str] = None

    lookup_key: Optional[str] = None

    metadata: Optional[Dict[str, str]] = None

    name: Optional[str] = None

    prices: Optional[List["DtoPriceResponse"]] = None
    r"""TODO: Add inline addons"""

    status: Optional[TypesStatus] = None

    tenant_id: Optional[str] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "created_at",
                "created_by",
                "credit_grants",
                "description",
                "display_order",
                "entitlements",
                "environment_id",
                "id",
                "lookup_key",
                "metadata",
                "name",
                "prices",
                "status",
                "tenant_id",
                "updated_at",
                "updated_by",
            ]
        )
        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
