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

from ..models.document_flag_level import DocumentFlagLevel
from ..types import UNSET, Unset

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


@_attrs_define
class DocumentFlag:
    """
    Attributes:
        timestamp (datetime.datetime | Unset):
        title (str | Unset):
        description (str | Unset):
        level (DocumentFlagLevel | Unset):
        pages (list[float] | Unset):
    """

    timestamp: datetime.datetime | Unset = UNSET
    title: str | Unset = UNSET
    description: str | Unset = UNSET
    level: DocumentFlagLevel | Unset = UNSET
    pages: list[float] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        timestamp: str | Unset = UNSET
        if not isinstance(self.timestamp, Unset):
            timestamp = self.timestamp.isoformat()

        title = self.title

        description = self.description

        level: str | Unset = UNSET
        if not isinstance(self.level, Unset):
            level = self.level.value

        pages: list[float] | Unset = UNSET
        if not isinstance(self.pages, Unset):
            pages = self.pages

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if timestamp is not UNSET:
            field_dict["timestamp"] = timestamp
        if title is not UNSET:
            field_dict["title"] = title
        if description is not UNSET:
            field_dict["description"] = description
        if level is not UNSET:
            field_dict["level"] = level
        if pages is not UNSET:
            field_dict["pages"] = pages

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        _timestamp = d.pop("timestamp", UNSET)
        timestamp: datetime.datetime | Unset
        if isinstance(_timestamp, Unset):
            timestamp = UNSET
        else:
            timestamp = isoparse(_timestamp)

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

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

        _level = d.pop("level", UNSET)
        level: DocumentFlagLevel | Unset
        if isinstance(_level, Unset):
            level = UNSET
        else:
            level = DocumentFlagLevel(_level)

        pages = cast(list[float], d.pop("pages", UNSET))

        document_flag = cls(
            timestamp=timestamp,
            title=title,
            description=description,
            level=level,
            pages=pages,
        )

        document_flag.additional_properties = d
        return document_flag

    @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
