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.workspace_role import WorkspaceRole

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


@_attrs_define
class UpdateWorkspaceUserRolesRequest:
    """Request to update user roles in a workspace (PATCH /workspace/{id}/users).

    All specified users are updated to the same role.

        Attributes:
            user_ext_ids (list[str]):
            role (WorkspaceRole): Role of a user within a workspace.
    """

    user_ext_ids: list[str]
    role: WorkspaceRole
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        role = self.role.value

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "user_ext_ids": user_ext_ids,
                "role": role,
            }
        )

        return field_dict

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

        role = WorkspaceRole(d.pop("role"))

        update_workspace_user_roles_request = cls(
            user_ext_ids=user_ext_ids,
            role=role,
        )

        update_workspace_user_roles_request.additional_properties = d
        return update_workspace_user_roles_request

    @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
