from __future__ import annotations

import datetime
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 dateutil.parser import isoparse

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


@_attrs_define
class GetAccountData:
    """
    Attributes:
        credits_ (int):
        note (None | str):
        expires (datetime.datetime):
        expires_unix (float):
        key (str):
        user (str):
    """

    credits_: int
    note: None | str
    expires: datetime.datetime
    expires_unix: float
    key: str
    user: str
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        note: None | str
        note = self.note

        expires = self.expires.isoformat()

        expires_unix = self.expires_unix

        key = self.key

        user = self.user

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({
            "credits": credits_,
            "note": note,
            "expires": expires,
            "expires_unix": expires_unix,
            "key": key,
            "user": user,
        })

        return field_dict

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

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

        note = _parse_note(d.pop("note"))

        expires = isoparse(d.pop("expires"))

        expires_unix = d.pop("expires_unix")

        key = d.pop("key")

        user = d.pop("user")

        get_account_data = cls(
            credits_=credits_,
            note=note,
            expires=expires,
            expires_unix=expires_unix,
            key=key,
            user=user,
        )

        get_account_data.additional_properties = d
        return get_account_data

    @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
