# coding: utf-8

"""
    WordLift API

    WordLift API

    The version of the OpenAPI document: 1.0
    Contact: hello@wordlift.io
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from wordlift_client.models.vector_search_query_response_item_fields_value_inner import VectorSearchQueryResponseItemFieldsValueInner
from wordlift_client.models.vector_search_query_response_item_metadata_value import VectorSearchQueryResponseItemMetadataValue
from typing import Optional, Set
from typing_extensions import Self

class VectorSearchQueryResponseItem(BaseModel):
    """
    An array of objects.
    """ # noqa: E501
    fields: Optional[Dict[str, List[VectorSearchQueryResponseItemFieldsValueInner]]] = Field(default=None, description="Map of extra retrieved fields. The values of the requested fields are always returned in an array.If no value is found an empty array is returned.")
    id: Optional[StrictStr] = None
    iri: StrictStr = Field(description="The IRI of the entity that this node belongs to.")
    metadata: Optional[Dict[str, VectorSearchQueryResponseItemMetadataValue]] = Field(default=None, description="A nodes extra metadata.")
    node_id: Optional[StrictStr] = Field(default=None, description="A nodes id.")
    score: Union[StrictFloat, StrictInt] = Field(description="The similarity score between the node and the query embeddings.")
    text: Optional[StrictStr] = Field(default=None, description="The text of a node from which the embeddings were generated.")
    __properties: ClassVar[List[str]] = ["fields", "id", "iri", "metadata", "node_id", "score", "text"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of VectorSearchQueryResponseItem from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each value in fields (dict of array)
        _field_dict_of_array = {}
        if self.fields:
            for _key in self.fields:
                if self.fields[_key] is not None:
                    _field_dict_of_array[_key] = [
                        _item.to_dict() for _item in self.fields[_key]
                    ]
            _dict['fields'] = _field_dict_of_array
        # override the default output from pydantic by calling `to_dict()` of each value in metadata (dict)
        _field_dict = {}
        if self.metadata:
            for _key in self.metadata:
                if self.metadata[_key]:
                    _field_dict[_key] = self.metadata[_key].to_dict()
            _dict['metadata'] = _field_dict
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of VectorSearchQueryResponseItem from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "fields": dict(
                (_k,
                        [VectorSearchQueryResponseItemFieldsValueInner.from_dict(_item) for _item in _v]
                        if _v is not None
                        else None
                )
                for _k, _v in obj.get("fields", {}).items()
            ),
            "id": obj.get("id"),
            "iri": obj.get("iri"),
            "metadata": dict(
                (_k, VectorSearchQueryResponseItemMetadataValue.from_dict(_v))
                for _k, _v in obj["metadata"].items()
            )
            if obj.get("metadata") is not None
            else None,
            "node_id": obj.get("node_id"),
            "score": obj.get("score"),
            "text": obj.get("text")
        })
        return _obj


