from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.note_thread import NoteThread


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


@_attrs_define
class DocumentNote:
    """
    Attributes:
        page (float | Unset):
        thread (list[NoteThread] | Unset):
        tags (list[str] | Unset):
        x (float | Unset):
        y (float | Unset):
    """

    page: float | Unset = UNSET
    thread: list[NoteThread] | Unset = UNSET
    tags: list[str] | Unset = UNSET
    x: float | Unset = UNSET
    y: float | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        thread: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.thread, Unset):
            thread = []
            for thread_item_data in self.thread:
                thread_item = thread_item_data.to_dict()
                thread.append(thread_item)

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

        x = self.x

        y = self.y

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if page is not UNSET:
            field_dict["page"] = page
        if thread is not UNSET:
            field_dict["thread"] = thread
        if tags is not UNSET:
            field_dict["tags"] = tags
        if x is not UNSET:
            field_dict["x"] = x
        if y is not UNSET:
            field_dict["y"] = y

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.note_thread import NoteThread

        d = dict(src_dict)
        page = d.pop("page", UNSET)

        _thread = d.pop("thread", UNSET)
        thread: list[NoteThread] | Unset = UNSET
        if _thread is not UNSET:
            thread = []
            for thread_item_data in _thread:
                thread_item = NoteThread.from_dict(thread_item_data)

                thread.append(thread_item)

        tags = cast(list[str], d.pop("tags", UNSET))

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

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

        document_note = cls(
            page=page,
            thread=thread,
            tags=tags,
            x=x,
            y=y,
        )

        document_note.additional_properties = d
        return document_note

    @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
