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

import attr

from ..types import UNSET, Unset

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


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

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


@attr.s(auto_attribs=True)
class Dashboard(uuid.Uuid):
    """ """

    name: "Union[Unset, str]" = UNSET
    owner: "Union[Unset, user_m.User]" = UNSET
    data: "Union[Unset, str]" = UNSET
    permission: "Union[Unset, str]" = UNSET
    access: "Union[Unset, str]" = UNSET
    permissions: "Union[Unset, List[dashboard_permission_m.DashboardPermission]]" = UNSET
    favorite: "Union[Unset, bool]" = UNSET
    ordinal: "Union[Unset, int]" = UNSET
    additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

    def to_dict(self) -> Dict[str, Any]:
        name = self.name
        owner: Union[Unset, Dict[str, Any]] = UNSET
        if not isinstance(self.owner, Unset):
            owner = self.owner.to_dict()

        data = self.data
        permission = self.permission
        access = self.access
        permissions: Union[Unset, List[Dict[str, Any]]] = UNSET
        if not isinstance(self.permissions, Unset):
            permissions = []
            for permissions_item_data in self.permissions:
                permissions_item = permissions_item_data.to_dict()

                permissions.append(permissions_item)

        favorite = self.favorite
        ordinal = self.ordinal

        field_dict: Dict[str, Any] = {}
        _Uuid_dict = super().to_dict()
        field_dict.update(_Uuid_dict)
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if name is not UNSET:
            field_dict["name"] = name
        if owner is not UNSET:
            field_dict["owner"] = owner
        if data is not UNSET:
            field_dict["data"] = data
        if permission is not UNSET:
            field_dict["permission"] = permission
        if access is not UNSET:
            field_dict["access"] = access
        if permissions is not UNSET:
            field_dict["permissions"] = permissions
        if favorite is not UNSET:
            field_dict["favorite"] = favorite
        if ordinal is not UNSET:
            field_dict["ordinal"] = ordinal

        return field_dict

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

        try:
            from ..models import dashboard_permission as dashboard_permission_m
            from ..models import user as user_m
        except ImportError:
            import sys

            dashboard_permission_m = sys.modules[__package__ + "dashboard_permission"]
            user_m = sys.modules[__package__ + "user"]

        d = src_dict.copy()

        name = d.pop("name", UNSET)

        _owner = d.pop("owner", UNSET)
        owner: Union[Unset, user_m.User]
        if isinstance(_owner, Unset):
            owner = UNSET
        else:
            owner = user_m.User.from_dict(_owner)

        data = d.pop("data", UNSET)

        permission = d.pop("permission", UNSET)

        access = d.pop("access", UNSET)

        permissions = []
        _permissions = d.pop("permissions", UNSET)
        for permissions_item_data in _permissions or []:
            permissions_item = dashboard_permission_m.DashboardPermission.from_dict(permissions_item_data)

            permissions.append(permissions_item)

        favorite = d.pop("favorite", UNSET)

        ordinal = d.pop("ordinal", UNSET)

        dashboard = cls(
            name=name,
            owner=owner,
            data=data,
            permission=permission,
            access=access,
            permissions=permissions,
            favorite=favorite,
            ordinal=ordinal,
        )

        dashboard.additional_properties = d
        return dashboard

    @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
