from typing import Any
from typing import cast
from typing import Dict
from typing import List
from typing import Type
from typing import TYPE_CHECKING
from typing import TypeVar
from typing import Union

from attrs import define as _attrs_define

from ..types import UNSET
from ..types import Unset

if TYPE_CHECKING:
    from ..models.new_collection_version_metadata import NewCollectionVersionMetadata


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


@_attrs_define
class NewCollectionVersion:
    """Collection version details

    Attributes:
        description (str): The description of the version
        item_ids (Union[Unset, List[str]]): The items to include in this collection version
        metadata (Union[Unset, NewCollectionVersionMetadata]): Arbitrary user-defined metadata, key-value pairs
    """

    description: str
    item_ids: Union[Unset, List[str]] = UNSET
    metadata: Union[Unset, "NewCollectionVersionMetadata"] = UNSET

    def to_dict(self) -> Dict[str, Any]:
        """Convert to a dict"""
        description = self.description
        item_ids: Union[Unset, List[str]] = UNSET
        if not isinstance(self.item_ids, Unset):
            item_ids = self.item_ids

        metadata: Union[Unset, Dict[str, Any]] = UNSET
        if not isinstance(self.metadata, Unset):
            metadata = self.metadata.to_dict()

        field_dict: Dict[str, Any] = {}
        field_dict.update(
            {
                "description": description,
            }
        )
        if item_ids is not UNSET:
            field_dict["itemIds"] = item_ids
        if metadata is not UNSET:
            field_dict["metadata"] = metadata

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
        """Create an instance of :py:class:`NewCollectionVersion` from a dict"""
        from ..models.new_collection_version_metadata import (
            NewCollectionVersionMetadata,
        )

        d = src_dict.copy()
        description = d.pop("description")

        item_ids = cast(List[str], d.pop("itemIds", UNSET))

        _metadata = d.pop("metadata", UNSET)
        metadata: Union[Unset, NewCollectionVersionMetadata]
        if isinstance(_metadata, Unset):
            metadata = UNSET
        else:
            metadata = NewCollectionVersionMetadata.from_dict(_metadata)

        new_collection_version = cls(
            description=description,
            item_ids=item_ids,
            metadata=metadata,
        )

        return new_collection_version
