from __future__ import annotations

import datetime
from collections.abc import Mapping
from typing import Any, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field
from dateutil.parser import isoparse

from ..types import UNSET, Unset

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


@_attrs_define
class TrustAccounting:
    """
    Attributes:
        enabled (bool | Unset):
        running (bool | Unset):
        last_run (datetime.datetime | Unset):
        tx_detail (str | Unset):
        dashboard (bool | Unset):
    """

    enabled: bool | Unset = UNSET
    running: bool | Unset = UNSET
    last_run: datetime.datetime | Unset = UNSET
    tx_detail: str | Unset = UNSET
    dashboard: bool | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        running = self.running

        last_run: str | Unset = UNSET
        if not isinstance(self.last_run, Unset):
            last_run = self.last_run.isoformat()

        tx_detail = self.tx_detail

        dashboard = self.dashboard

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if enabled is not UNSET:
            field_dict["enabled"] = enabled
        if running is not UNSET:
            field_dict["running"] = running
        if last_run is not UNSET:
            field_dict["lastRun"] = last_run
        if tx_detail is not UNSET:
            field_dict["txDetail"] = tx_detail
        if dashboard is not UNSET:
            field_dict["dashboard"] = dashboard

        return field_dict

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

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

        _last_run = d.pop("lastRun", UNSET)
        last_run: datetime.datetime | Unset
        if isinstance(_last_run, Unset):
            last_run = UNSET
        else:
            last_run = isoparse(_last_run)

        tx_detail = d.pop("txDetail", UNSET)

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

        trust_accounting = cls(
            enabled=enabled,
            running=running,
            last_run=last_run,
            tx_detail=tx_detail,
            dashboard=dashboard,
        )

        trust_accounting.additional_properties = d
        return trust_accounting

    @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
