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 ..types import UNSET, Unset

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


@_attrs_define
class ReadInfo:
    """
    Attributes:
        operation_urls (list[str] | Unset):
        fetch_time (datetime.datetime | Unset):
    """

    operation_urls: list[str] | Unset = UNSET
    fetch_time: datetime.datetime | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if operation_urls is not UNSET:
            field_dict["operationUrls"] = operation_urls
        if fetch_time is not UNSET:
            field_dict["fetchTime"] = fetch_time

        return field_dict

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

        _fetch_time = d.pop("fetchTime", UNSET)
        fetch_time: datetime.datetime | Unset
        if isinstance(_fetch_time, Unset):
            fetch_time = UNSET
        else:
            fetch_time = isoparse(_fetch_time)

        read_info = cls(
            operation_urls=operation_urls,
            fetch_time=fetch_time,
        )

        read_info.additional_properties = d
        return read_info

    @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
