from __future__ import annotations

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

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

from ..models.runnable_type import RunnableType
from ..types import UNSET, Unset

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


@_attrs_define
class ShareDataUpdate:
    """
    Attributes:
        data_id (None | str | Unset):
        runnable_type (None | RunnableType | Unset):
    """

    data_id: None | str | Unset = UNSET
    runnable_type: None | RunnableType | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        data_id: None | str | Unset
        if isinstance(self.data_id, Unset):
            data_id = UNSET
        else:
            data_id = self.data_id

        runnable_type: None | str | Unset
        if isinstance(self.runnable_type, Unset):
            runnable_type = UNSET
        elif isinstance(self.runnable_type, RunnableType):
            runnable_type = self.runnable_type.value
        else:
            runnable_type = self.runnable_type

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

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)

        def _parse_data_id(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        data_id = _parse_data_id(d.pop("data_id", UNSET))

        def _parse_runnable_type(data: object) -> None | RunnableType | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                runnable_type_type_0 = RunnableType(data)

                return runnable_type_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(None | RunnableType | Unset, data)

        runnable_type = _parse_runnable_type(d.pop("runnable_type", UNSET))

        share_data_update = cls(
            data_id=data_id,
            runnable_type=runnable_type,
        )

        share_data_update.additional_properties = d
        return share_data_update

    @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
