from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, BinaryIO, TextIO, TYPE_CHECKING, Generator

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

from ..types import UNSET, Unset
from typing import cast






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



@_attrs_define
class SessionInfoResponse:
    """ Active session info returned by GET /user/sessions.

        Attributes:
            sk (str):
            ttl (int):
            is_current (bool):
            ip_address (None | str | Unset):
            delegated (bool | Unset):  Default: False.
     """

    sk: str
    ttl: int
    is_current: bool
    ip_address: None | str | Unset = UNSET
    delegated: bool | Unset = False
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)





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

        ttl = self.ttl

        is_current = self.is_current

        ip_address: None | str | Unset
        if isinstance(self.ip_address, Unset):
            ip_address = UNSET
        else:
            ip_address = self.ip_address

        delegated = self.delegated


        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({
            "sk": sk,
            "ttl": ttl,
            "is_current": is_current,
        })
        if ip_address is not UNSET:
            field_dict["ip_address"] = ip_address
        if delegated is not UNSET:
            field_dict["delegated"] = delegated

        return field_dict



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

        ttl = d.pop("ttl")

        is_current = d.pop("is_current")

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

        ip_address = _parse_ip_address(d.pop("ip_address", UNSET))


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

        session_info_response = cls(
            sk=sk,
            ttl=ttl,
            is_current=is_current,
            ip_address=ip_address,
            delegated=delegated,
        )


        session_info_response.additional_properties = d
        return session_info_response

    @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
