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

if TYPE_CHECKING:
    from ..models.change_password_request_rewrapped_workspace_keys import ChangePasswordRequestRewrappedWorkspaceKeys


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


@_attrs_define
class ChangePasswordRequest:
    """Password change request with signature-based auth.

    Client proves knowledge of current password by signing with Ed25519 key.
    Server derives new X25519 encryption key from new Ed25519 signing key.

        Attributes:
            signature (str):
            timestamp (int):
            new_signing_key (str):
            rewrapped_workspace_keys (ChangePasswordRequestRewrappedWorkspaceKeys):
    """

    signature: str
    timestamp: int
    new_signing_key: str
    rewrapped_workspace_keys: ChangePasswordRequestRewrappedWorkspaceKeys
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        timestamp = self.timestamp

        new_signing_key = self.new_signing_key

        rewrapped_workspace_keys = self.rewrapped_workspace_keys.to_dict()

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "signature": signature,
                "timestamp": timestamp,
                "new_signing_key": new_signing_key,
                "rewrapped_workspace_keys": rewrapped_workspace_keys,
            }
        )

        return field_dict

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

        d = dict(src_dict)
        signature = d.pop("signature")

        timestamp = d.pop("timestamp")

        new_signing_key = d.pop("new_signing_key")

        rewrapped_workspace_keys = ChangePasswordRequestRewrappedWorkspaceKeys.from_dict(
            d.pop("rewrapped_workspace_keys")
        )

        change_password_request = cls(
            signature=signature,
            timestamp=timestamp,
            new_signing_key=new_signing_key,
            rewrapped_workspace_keys=rewrapped_workspace_keys,
        )

        change_password_request.additional_properties = d
        return change_password_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
