"""
This file is generated by the openapi-python-client tool via the generate_api_client.py script

It is a customized template from the openapi-python-client tool's default template:
https://github.com/openapi-generators/openapi-python-client/blob/861ef5622f10fc96d240dc9becb0edf94e61446c/openapi_python_client/templates/model.py.jinja

The main change is:
- Fix typing issues
"""

# flake8: noqa: C901

import datetime
from enum import Enum
from typing import TYPE_CHECKING, Any, List, Type, TypeVar, Union, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field
from dateutil.parser import isoparse

from ..models.memory_type import MemoryType
from ..models.memoryset_metadata_index_type import MemorysetMetadataIndexType
from ..models.pretrained_embedding_model_name import PretrainedEmbeddingModelName
from ..models.task_status import TaskStatus

if TYPE_CHECKING:
    from ..models.memoryset_metadata_index_params import MemorysetMetadataIndexParams
    from ..models.memoryset_metrics import MemorysetMetrics


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


@_attrs_define
class MemorysetMetadata:
    """
    Attributes:
        id (str):
        org_id (str):
        collection_name (str):
        name (str):
        description (Union[None, str]):
        notes (Union[None, str]):
        length (int):
        pretrained_embedding_model_name (Union[None, PretrainedEmbeddingModelName]):
        finetuned_embedding_model_id (Union[None, str]):
        created_at (datetime.datetime):
        updated_at (datetime.datetime):
        memories_updated_at (datetime.datetime):
        insertion_task_id (str):
        insertion_status (TaskStatus): Status of task in the task queue
        metrics (MemorysetMetrics):
        memory_type (MemoryType):
        label_names (Union[List[str], None]):
        index_type (MemorysetMetadataIndexType):
        index_params (MemorysetMetadataIndexParams):
        database_uri (Union[None, str]):
        document_prompt_override (Union[None, str]):
        query_prompt_override (Union[None, str]):
    """

    id: str
    org_id: str
    collection_name: str
    name: str
    description: Union[None, str]
    notes: Union[None, str]
    length: int
    pretrained_embedding_model_name: Union[None, PretrainedEmbeddingModelName]
    finetuned_embedding_model_id: Union[None, str]
    created_at: datetime.datetime
    updated_at: datetime.datetime
    memories_updated_at: datetime.datetime
    insertion_task_id: str
    insertion_status: TaskStatus
    metrics: "MemorysetMetrics"
    memory_type: MemoryType
    label_names: Union[List[str], None]
    index_type: MemorysetMetadataIndexType
    index_params: "MemorysetMetadataIndexParams"
    database_uri: Union[None, str]
    document_prompt_override: Union[None, str]
    query_prompt_override: Union[None, str]
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        org_id = self.org_id

        collection_name = self.collection_name

        name = self.name

        description: Union[None, str]
        description = self.description

        notes: Union[None, str]
        notes = self.notes

        length = self.length

        pretrained_embedding_model_name: Union[None, str]
        if isinstance(self.pretrained_embedding_model_name, PretrainedEmbeddingModelName):
            pretrained_embedding_model_name = (
                self.pretrained_embedding_model_name.value
                if isinstance(self.pretrained_embedding_model_name, Enum)
                else self.pretrained_embedding_model_name
            )
        else:
            pretrained_embedding_model_name = self.pretrained_embedding_model_name

        finetuned_embedding_model_id: Union[None, str]
        finetuned_embedding_model_id = self.finetuned_embedding_model_id

        created_at = self.created_at.isoformat()

        updated_at = self.updated_at.isoformat()

        memories_updated_at = self.memories_updated_at.isoformat()

        insertion_task_id = self.insertion_task_id

        insertion_status = (
            self.insertion_status.value if isinstance(self.insertion_status, Enum) else self.insertion_status
        )

        metrics = self.metrics.to_dict()

        memory_type = self.memory_type.value if isinstance(self.memory_type, Enum) else self.memory_type

        label_names: Union[List[str], None]
        if isinstance(self.label_names, list):
            label_names = self.label_names

        else:
            label_names = self.label_names

        index_type = self.index_type.value if isinstance(self.index_type, Enum) else self.index_type

        index_params = self.index_params.to_dict()

        database_uri: Union[None, str]
        database_uri = self.database_uri

        document_prompt_override: Union[None, str]
        document_prompt_override = self.document_prompt_override

        query_prompt_override: Union[None, str]
        query_prompt_override = self.query_prompt_override

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "id": id,
                "org_id": org_id,
                "collection_name": collection_name,
                "name": name,
                "description": description,
                "notes": notes,
                "length": length,
                "pretrained_embedding_model_name": pretrained_embedding_model_name,
                "finetuned_embedding_model_id": finetuned_embedding_model_id,
                "created_at": created_at,
                "updated_at": updated_at,
                "memories_updated_at": memories_updated_at,
                "insertion_task_id": insertion_task_id,
                "insertion_status": insertion_status,
                "metrics": metrics,
                "memory_type": memory_type,
                "label_names": label_names,
                "index_type": index_type,
                "index_params": index_params,
                "database_uri": database_uri,
                "document_prompt_override": document_prompt_override,
                "query_prompt_override": query_prompt_override,
            }
        )

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: dict[str, Any]) -> T:
        from ..models.memoryset_metadata_index_params import MemorysetMetadataIndexParams
        from ..models.memoryset_metrics import MemorysetMetrics

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

        org_id = d.pop("org_id")

        collection_name = d.pop("collection_name")

        name = d.pop("name")

        def _parse_description(data: object) -> Union[None, str]:
            if data is None:
                return data
            return cast(Union[None, str], data)

        description = _parse_description(d.pop("description"))

        def _parse_notes(data: object) -> Union[None, str]:
            if data is None:
                return data
            return cast(Union[None, str], data)

        notes = _parse_notes(d.pop("notes"))

        length = d.pop("length")

        def _parse_pretrained_embedding_model_name(data: object) -> Union[None, PretrainedEmbeddingModelName]:
            if data is None:
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                pretrained_embedding_model_name_type_0 = PretrainedEmbeddingModelName(data)

                return pretrained_embedding_model_name_type_0
            except:  # noqa: E722
                pass
            return cast(Union[None, PretrainedEmbeddingModelName], data)

        pretrained_embedding_model_name = _parse_pretrained_embedding_model_name(
            d.pop("pretrained_embedding_model_name")
        )

        def _parse_finetuned_embedding_model_id(data: object) -> Union[None, str]:
            if data is None:
                return data
            return cast(Union[None, str], data)

        finetuned_embedding_model_id = _parse_finetuned_embedding_model_id(d.pop("finetuned_embedding_model_id"))

        created_at = isoparse(d.pop("created_at"))

        updated_at = isoparse(d.pop("updated_at"))

        memories_updated_at = isoparse(d.pop("memories_updated_at"))

        insertion_task_id = d.pop("insertion_task_id")

        insertion_status = TaskStatus(d.pop("insertion_status"))

        metrics = MemorysetMetrics.from_dict(d.pop("metrics"))

        memory_type = MemoryType(d.pop("memory_type"))

        def _parse_label_names(data: object) -> Union[List[str], None]:
            if data is None:
                return data
            try:
                if not isinstance(data, list):
                    raise TypeError()
                label_names_type_0 = cast(List[str], data)

                return label_names_type_0
            except:  # noqa: E722
                pass
            return cast(Union[List[str], None], data)

        label_names = _parse_label_names(d.pop("label_names"))

        index_type = MemorysetMetadataIndexType(d.pop("index_type"))

        index_params = MemorysetMetadataIndexParams.from_dict(d.pop("index_params"))

        def _parse_database_uri(data: object) -> Union[None, str]:
            if data is None:
                return data
            return cast(Union[None, str], data)

        database_uri = _parse_database_uri(d.pop("database_uri"))

        def _parse_document_prompt_override(data: object) -> Union[None, str]:
            if data is None:
                return data
            return cast(Union[None, str], data)

        document_prompt_override = _parse_document_prompt_override(d.pop("document_prompt_override"))

        def _parse_query_prompt_override(data: object) -> Union[None, str]:
            if data is None:
                return data
            return cast(Union[None, str], data)

        query_prompt_override = _parse_query_prompt_override(d.pop("query_prompt_override"))

        memoryset_metadata = cls(
            id=id,
            org_id=org_id,
            collection_name=collection_name,
            name=name,
            description=description,
            notes=notes,
            length=length,
            pretrained_embedding_model_name=pretrained_embedding_model_name,
            finetuned_embedding_model_id=finetuned_embedding_model_id,
            created_at=created_at,
            updated_at=updated_at,
            memories_updated_at=memories_updated_at,
            insertion_task_id=insertion_task_id,
            insertion_status=insertion_status,
            metrics=metrics,
            memory_type=memory_type,
            label_names=label_names,
            index_type=index_type,
            index_params=index_params,
            database_uri=database_uri,
            document_prompt_override=document_prompt_override,
            query_prompt_override=query_prompt_override,
        )

        memoryset_metadata.additional_properties = d
        return memoryset_metadata

    @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
