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.document_update_body_doc_diff import DocumentUpdateBodyDocDiff


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


@_attrs_define
class DocumentUpdateBody:
    """
    Attributes:
        doc_diff (DocumentUpdateBodyDocDiff): Fields to update
        doc_id (str | Unset): MongoDB ObjectId
        doc_ids (list[str] | Unset): Multiple document IDs for bulk update
    """

    doc_diff: DocumentUpdateBodyDocDiff
    doc_id: str | Unset = UNSET
    doc_ids: list[str] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        doc_id = self.doc_id

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "docDiff": doc_diff,
            }
        )
        if doc_id is not UNSET:
            field_dict["docId"] = doc_id
        if doc_ids is not UNSET:
            field_dict["docIds"] = doc_ids

        return field_dict

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

        d = dict(src_dict)
        doc_diff = DocumentUpdateBodyDocDiff.from_dict(d.pop("docDiff"))

        doc_id = d.pop("docId", UNSET)

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

        document_update_body = cls(
            doc_diff=doc_diff,
            doc_id=doc_id,
            doc_ids=doc_ids,
        )

        document_update_body.additional_properties = d
        return document_update_body

    @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
