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.tool_resources_file_search_vector_store_chunking_strategy_auto import (
        ToolResourcesFileSearchVectorStoreChunkingStrategyAuto,
    )
    from ..models.tool_resources_file_search_vector_store_chunking_strategy_static import (
        ToolResourcesFileSearchVectorStoreChunkingStrategyStatic,
    )
    from ..models.tool_resources_file_search_vector_store_metadata_type_0 import (
        ToolResourcesFileSearchVectorStoreMetadataType0,
    )


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


@_attrs_define
class ToolResourcesFileSearchVectorStore:
    """
    Attributes:
        chunking_strategy (ToolResourcesFileSearchVectorStoreChunkingStrategyAuto |
            ToolResourcesFileSearchVectorStoreChunkingStrategyStatic | Unset):
        file_ids (list[str] | Unset):
        metadata (None | ToolResourcesFileSearchVectorStoreMetadataType0 | Unset):
    """

    chunking_strategy: (
        ToolResourcesFileSearchVectorStoreChunkingStrategyAuto
        | ToolResourcesFileSearchVectorStoreChunkingStrategyStatic
        | Unset
    ) = UNSET
    file_ids: list[str] | Unset = UNSET
    metadata: None | ToolResourcesFileSearchVectorStoreMetadataType0 | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        from ..models.tool_resources_file_search_vector_store_chunking_strategy_auto import (
            ToolResourcesFileSearchVectorStoreChunkingStrategyAuto,
        )
        from ..models.tool_resources_file_search_vector_store_metadata_type_0 import (
            ToolResourcesFileSearchVectorStoreMetadataType0,
        )

        chunking_strategy: dict[str, Any] | Unset
        if isinstance(self.chunking_strategy, Unset):
            chunking_strategy = UNSET
        elif isinstance(self.chunking_strategy, ToolResourcesFileSearchVectorStoreChunkingStrategyAuto):
            chunking_strategy = self.chunking_strategy.to_dict()
        else:
            chunking_strategy = self.chunking_strategy.to_dict()

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

        metadata: dict[str, Any] | None | Unset
        if isinstance(self.metadata, Unset):
            metadata = UNSET
        elif isinstance(self.metadata, ToolResourcesFileSearchVectorStoreMetadataType0):
            metadata = self.metadata.to_dict()
        else:
            metadata = self.metadata

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if chunking_strategy is not UNSET:
            field_dict["chunking_strategy"] = chunking_strategy
        if file_ids is not UNSET:
            field_dict["file_ids"] = file_ids
        if metadata is not UNSET:
            field_dict["metadata"] = metadata

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.tool_resources_file_search_vector_store_chunking_strategy_auto import (
            ToolResourcesFileSearchVectorStoreChunkingStrategyAuto,
        )
        from ..models.tool_resources_file_search_vector_store_chunking_strategy_static import (
            ToolResourcesFileSearchVectorStoreChunkingStrategyStatic,
        )
        from ..models.tool_resources_file_search_vector_store_metadata_type_0 import (
            ToolResourcesFileSearchVectorStoreMetadataType0,
        )

        d = dict(src_dict)

        def _parse_chunking_strategy(
            data: object,
        ) -> (
            ToolResourcesFileSearchVectorStoreChunkingStrategyAuto
            | ToolResourcesFileSearchVectorStoreChunkingStrategyStatic
            | Unset
        ):
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                chunking_strategy_type_0 = ToolResourcesFileSearchVectorStoreChunkingStrategyAuto.from_dict(data)

                return chunking_strategy_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            if not isinstance(data, dict):
                raise TypeError()
            chunking_strategy_type_1 = ToolResourcesFileSearchVectorStoreChunkingStrategyStatic.from_dict(data)

            return chunking_strategy_type_1

        chunking_strategy = _parse_chunking_strategy(d.pop("chunking_strategy", UNSET))

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

        def _parse_metadata(data: object) -> None | ToolResourcesFileSearchVectorStoreMetadataType0 | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                metadata_type_0 = ToolResourcesFileSearchVectorStoreMetadataType0.from_dict(data)

                return metadata_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(None | ToolResourcesFileSearchVectorStoreMetadataType0 | Unset, data)

        metadata = _parse_metadata(d.pop("metadata", UNSET))

        tool_resources_file_search_vector_store = cls(
            chunking_strategy=chunking_strategy,
            file_ids=file_ids,
            metadata=metadata,
        )

        tool_resources_file_search_vector_store.additional_properties = d
        return tool_resources_file_search_vector_store

    @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
