from __future__ import annotations

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

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

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.metadata import Metadata


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


@_attrs_define
class DocumentCreateBody:
    """
    Attributes:
        name (str):
        stack_id (str | Unset): MongoDB ObjectId
        source (str | Unset):
        metadata (list[Metadata] | Unset):
        import_key (str | Unset):
    """

    name: str
    stack_id: str | Unset = UNSET
    source: str | Unset = UNSET
    metadata: list[Metadata] | Unset = UNSET
    import_key: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        stack_id = self.stack_id

        source = self.source

        metadata: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.metadata, Unset):
            metadata = []
            for metadata_item_data in self.metadata:
                metadata_item = metadata_item_data.to_dict()
                metadata.append(metadata_item)

        import_key = self.import_key

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "name": name,
            }
        )
        if stack_id is not UNSET:
            field_dict["stackId"] = stack_id
        if source is not UNSET:
            field_dict["source"] = source
        if metadata is not UNSET:
            field_dict["metadata"] = metadata
        if import_key is not UNSET:
            field_dict["importKey"] = import_key

        return field_dict

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

        d = dict(src_dict)
        name = d.pop("name")

        stack_id = d.pop("stackId", UNSET)

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

        _metadata = d.pop("metadata", UNSET)
        metadata: list[Metadata] | Unset = UNSET
        if _metadata is not UNSET:
            metadata = []
            for metadata_item_data in _metadata:
                metadata_item = Metadata.from_dict(metadata_item_data)

                metadata.append(metadata_item)

        import_key = d.pop("importKey", UNSET)

        document_create_body = cls(
            name=name,
            stack_id=stack_id,
            source=source,
            metadata=metadata,
            import_key=import_key,
        )

        document_create_body.additional_properties = d
        return document_create_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
