from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..models.plan_tier import PlanTier
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.plan_limits import PlanLimits
    from ..models.stripe_config import StripeConfig


T = TypeVar("T", bound="Plan")


@_attrs_define
class Plan:
    """
    Attributes:
        tier (PlanTier | Unset):
        stripe (StripeConfig | Unset):
        limits (PlanLimits | Unset):
    """

    tier: PlanTier | Unset = UNSET
    stripe: StripeConfig | Unset = UNSET
    limits: PlanLimits | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        tier: str | Unset = UNSET
        if not isinstance(self.tier, Unset):
            tier = self.tier.value

        stripe: dict[str, Any] | Unset = UNSET
        if not isinstance(self.stripe, Unset):
            stripe = self.stripe.to_dict()

        limits: dict[str, Any] | Unset = UNSET
        if not isinstance(self.limits, Unset):
            limits = self.limits.to_dict()

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if tier is not UNSET:
            field_dict["tier"] = tier
        if stripe is not UNSET:
            field_dict["stripe"] = stripe
        if limits is not UNSET:
            field_dict["limits"] = limits

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.plan_limits import PlanLimits
        from ..models.stripe_config import StripeConfig

        d = dict(src_dict)
        _tier = d.pop("tier", UNSET)
        tier: PlanTier | Unset
        if isinstance(_tier, Unset):
            tier = UNSET
        else:
            tier = PlanTier(_tier)

        _stripe = d.pop("stripe", UNSET)
        stripe: StripeConfig | Unset
        if isinstance(_stripe, Unset):
            stripe = UNSET
        else:
            stripe = StripeConfig.from_dict(_stripe)

        _limits = d.pop("limits", UNSET)
        limits: PlanLimits | Unset
        if isinstance(_limits, Unset):
            limits = UNSET
        else:
            limits = PlanLimits.from_dict(_limits)

        plan = cls(
            tier=tier,
            stripe=stripe,
            limits=limits,
        )

        plan.additional_properties = d
        return plan

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
