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="Trainer")


@_attrs_define
class Trainer:
    """
    Attributes:
        manual_trigger (bool | Unset):
        is_training (bool | Unset):
        last_trained (datetime.datetime | Unset):
    """

    manual_trigger: bool | Unset = UNSET
    is_training: bool | Unset = UNSET
    last_trained: datetime.datetime | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        is_training = self.is_training

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if manual_trigger is not UNSET:
            field_dict["manualTrigger"] = manual_trigger
        if is_training is not UNSET:
            field_dict["isTraining"] = is_training
        if last_trained is not UNSET:
            field_dict["lastTrained"] = last_trained

        return field_dict

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

        is_training = d.pop("isTraining", UNSET)

        _last_trained = d.pop("lastTrained", UNSET)
        last_trained: datetime.datetime | Unset
        if isinstance(_last_trained, Unset):
            last_trained = UNSET
        else:
            last_trained = isoparse(_last_trained)

        trainer = cls(
            manual_trigger=manual_trigger,
            is_training=is_training,
            last_trained=last_trained,
        )

        trainer.additional_properties = d
        return trainer

    @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
