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


@_attrs_define
class Recipient:
    """
    Attributes:
        document (str | Unset): MongoDB ObjectId
        email (str | Unset):
        name (str | Unset):
        sent_on (datetime.datetime | Unset):
        viewed_on (datetime.datetime | Unset):
        filled_on (datetime.datetime | Unset):
    """

    document: str | Unset = UNSET
    email: str | Unset = UNSET
    name: str | Unset = UNSET
    sent_on: datetime.datetime | Unset = UNSET
    viewed_on: datetime.datetime | Unset = UNSET
    filled_on: datetime.datetime | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        email = self.email

        name = self.name

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

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

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if document is not UNSET:
            field_dict["document"] = document
        if email is not UNSET:
            field_dict["email"] = email
        if name is not UNSET:
            field_dict["name"] = name
        if sent_on is not UNSET:
            field_dict["sentOn"] = sent_on
        if viewed_on is not UNSET:
            field_dict["viewedOn"] = viewed_on
        if filled_on is not UNSET:
            field_dict["filledOn"] = filled_on

        return field_dict

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

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

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

        _sent_on = d.pop("sentOn", UNSET)
        sent_on: datetime.datetime | Unset
        if isinstance(_sent_on, Unset):
            sent_on = UNSET
        else:
            sent_on = isoparse(_sent_on)

        _viewed_on = d.pop("viewedOn", UNSET)
        viewed_on: datetime.datetime | Unset
        if isinstance(_viewed_on, Unset):
            viewed_on = UNSET
        else:
            viewed_on = isoparse(_viewed_on)

        _filled_on = d.pop("filledOn", UNSET)
        filled_on: datetime.datetime | Unset
        if isinstance(_filled_on, Unset):
            filled_on = UNSET
        else:
            filled_on = isoparse(_filled_on)

        recipient = cls(
            document=document,
            email=email,
            name=name,
            sent_on=sent_on,
            viewed_on=viewed_on,
            filled_on=filled_on,
        )

        recipient.additional_properties = d
        return recipient

    @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
