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 ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.access_record import AccessRecord
    from ..models.protected_sharing import ProtectedSharing


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


@_attrs_define
class DocumentSharing:
    """
    Attributes:
        public (bool | Unset):
        protected (ProtectedSharing | Unset):
        access (list[AccessRecord] | Unset):
    """

    public: bool | Unset = UNSET
    protected: ProtectedSharing | Unset = UNSET
    access: list[AccessRecord] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        public = self.public

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

        access: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.access, Unset):
            access = []
            for access_item_data in self.access:
                access_item = access_item_data.to_dict()
                access.append(access_item)

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

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.access_record import AccessRecord
        from ..models.protected_sharing import ProtectedSharing

        d = dict(src_dict)
        public = d.pop("public", UNSET)

        _protected = d.pop("protected", UNSET)
        protected: ProtectedSharing | Unset
        if isinstance(_protected, Unset):
            protected = UNSET
        else:
            protected = ProtectedSharing.from_dict(_protected)

        _access = d.pop("access", UNSET)
        access: list[AccessRecord] | Unset = UNSET
        if _access is not UNSET:
            access = []
            for access_item_data in _access:
                access_item = AccessRecord.from_dict(access_item_data)

                access.append(access_item)

        document_sharing = cls(
            public=public,
            protected=protected,
            access=access,
        )

        document_sharing.additional_properties = d
        return document_sharing

    @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
