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

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


@_attrs_define
class UserSpaceBatchUpdate:
    """
    Attributes:
        user_spaces (list[int]):
        group_set (list[int]):
        household (int | None | Unset):
    """

    user_spaces: list[int]
    group_set: list[int]
    household: int | None | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        group_set = self.group_set

        household: int | None | Unset
        if isinstance(self.household, Unset):
            household = UNSET
        else:
            household = self.household

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

        return field_dict

    def to_multipart(self) -> types.RequestFiles:
        files: types.RequestFiles = []

        for user_spaces_item_element in self.user_spaces:
            files.append(("user_spaces", (None, str(user_spaces_item_element).encode(), "text/plain")))

        for group_set_item_element in self.group_set:
            files.append(("group_set", (None, str(group_set_item_element).encode(), "text/plain")))

        if not isinstance(self.household, Unset):
            if isinstance(self.household, int):
                files.append(("household", (None, str(self.household).encode(), "text/plain")))
            else:
                files.append(("household", (None, str(self.household).encode(), "text/plain")))

        for prop_name, prop in self.additional_properties.items():
            files.append((prop_name, (None, str(prop).encode(), "text/plain")))

        return files

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        user_spaces = cast(list[int], d.pop("user_spaces"))

        group_set = cast(list[int], d.pop("group_set"))

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

        household = _parse_household(d.pop("household", UNSET))

        user_space_batch_update = cls(
            user_spaces=user_spaces,
            group_set=group_set,
            household=household,
        )

        user_space_batch_update.additional_properties = d
        return user_space_batch_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
