from typing import Any, Dict, Type, TypeVar, Union

import attr

from ..types import UNSET, Unset

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


try:
    from ..models import bundle_element
except ImportError:
    import sys

    bundle_element = sys.modules[__package__ + "bundle_element"]


@attr.s(auto_attribs=True)
class LocalizableBundleElement(bundle_element.BundleElement):
    """Represents field value that can be localized."""

    localized_name: "Union[Unset, str]" = UNSET

    def to_dict(self) -> Dict[str, Any]:
        localized_name = self.localized_name

        field_dict: Dict[str, Any] = {}
        _BundleElement_dict = super().to_dict()
        field_dict.update(_BundleElement_dict)
        field_dict.update({})
        if localized_name is not UNSET:
            field_dict["localizedName"] = localized_name

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:

        d = src_dict.copy()

        _BundleElement_kwargs = super().from_dict(src_dict=d).to_dict()
        _BundleElement_kwargs.pop("$type")

        localized_name = d.pop("localizedName", UNSET)

        localizable_bundle_element = cls(
            localized_name=localized_name,
            **_BundleElement_kwargs,
        )

        return localizable_bundle_element
