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

from __future__ import annotations
from .addonassociationentitytype import AddonAssociationEntityType
from .addonstatus import AddonStatus
from .dto_addonresponse import DtoAddonResponse, DtoAddonResponseTypedDict
from .dto_subscriptionresponse import (
    DtoSubscriptionResponse,
    DtoSubscriptionResponseTypedDict,
)
from .status import Status
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Any, Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoAddonAssociationResponseTypedDict(TypedDict):
    addon: NotRequired[DtoAddonResponseTypedDict]
    addon_id: NotRequired[str]
    addon_status: NotRequired[AddonStatus]
    cancellation_reason: NotRequired[str]
    cancelled_at: NotRequired[str]
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    end_date: NotRequired[str]
    entity_id: NotRequired[str]
    entity_type: NotRequired[AddonAssociationEntityType]
    environment_id: NotRequired[str]
    id: NotRequired[str]
    metadata: NotRequired[Dict[str, Any]]
    start_date: NotRequired[str]
    status: NotRequired[Status]
    subscription: NotRequired[DtoSubscriptionResponseTypedDict]
    tenant_id: NotRequired[str]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


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

    addon_id: Optional[str] = None

    addon_status: Optional[AddonStatus] = None

    cancellation_reason: Optional[str] = None

    cancelled_at: Optional[str] = None

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    end_date: Optional[str] = None

    entity_id: Optional[str] = None

    entity_type: Optional[AddonAssociationEntityType] = None

    environment_id: Optional[str] = None

    id: Optional[str] = None

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

    start_date: Optional[str] = None

    status: Optional[Status] = None

    subscription: Optional[DtoSubscriptionResponse] = 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(
            [
                "addon",
                "addon_id",
                "addon_status",
                "cancellation_reason",
                "cancelled_at",
                "created_at",
                "created_by",
                "end_date",
                "entity_id",
                "entity_type",
                "environment_id",
                "id",
                "metadata",
                "start_date",
                "status",
                "subscription",
                "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, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
