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

import attr

from ..types import UNSET, Unset

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


@attr.s(auto_attribs=True)
class V20CredAttrSpec:
    """
    Attributes:
        name (str): Attribute name Example: favourite_drink.
        value (str): Attribute value: base64-encode if MIME type is present Example: martini.
        mime_type (Union[Unset, None, str]): MIME type: omit for (null) default Example: image/jpeg.
    """

    name: str
    value: str
    mime_type: Union[Unset, None, str] = UNSET
    additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

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

        field_dict: Dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "name": name,
                "value": value,
            }
        )
        if mime_type is not UNSET:
            field_dict["mime-type"] = mime_type

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
        d = src_dict.copy()
        name = d.pop("name")

        value = d.pop("value")

        mime_type = d.pop("mime-type", UNSET)

        v20_cred_attr_spec = cls(
            name=name,
            value=value,
            mime_type=mime_type,
        )

        v20_cred_attr_spec.additional_properties = d
        return v20_cred_attr_spec

    @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
