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.category_ref import CategoryRef


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


@_attrs_define
class AccessRestrictionAttributes:
    """
    Attributes:
        categories (list[CategoryRef] | Unset): The list of place categories, this set of access restrictions refers to.
        restricted (bool | Unset): When set to `true`, the place response item has a known access restriction.
            When the place has no known access restriction, the `accessRestrictions` element is omitted, so `restricted`
            value is never set to `false`.
    """

    categories: list[CategoryRef] | Unset = UNSET
    restricted: bool | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        categories: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.categories, Unset):
            categories = []
            for categories_item_data in self.categories:
                categories_item = categories_item_data.to_dict()
                categories.append(categories_item)

        restricted = self.restricted

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

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.category_ref import CategoryRef

        d = dict(src_dict)
        _categories = d.pop("categories", UNSET)
        categories: list[CategoryRef] | Unset = UNSET
        if _categories is not UNSET:
            categories = []
            for categories_item_data in _categories:
                categories_item = CategoryRef.from_dict(categories_item_data)

                categories.append(categories_item)

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

        access_restriction_attributes = cls(
            categories=categories,
            restricted=restricted,
        )

        access_restriction_attributes.additional_properties = d
        return access_restriction_attributes

    @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
