# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.com
    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
from typing import Any, ClassVar, Dict, List
from typing_extensions import Annotated
from mixpeek.models.vector_index import VectorIndex
from typing import Optional, Set
from typing_extensions import Self

class MultiVectorIndex(BaseModel):
    """
    Configuration for multi-vector indexes.  Allows a single extractor to produce multiple named vector outputs in one index. Useful for hybrid search combining different embedding types or multiple models.  Use Cases:     - Hybrid dense + sparse embeddings in one index     - Multiple models for ensemble retrieval     - Different granularities (sentence + paragraph embeddings)  Requirements:     - name: REQUIRED - Full qualified name for the multi-vector index     - description: REQUIRED - Explain what vector combinations are included     - vectors: REQUIRED - Dictionary mapping output names to VectorIndex configs  Note: Currently less common than single VectorIndex. Most extractors use separate VectorIndexDefinitions for each output instead.
    """ # noqa: E501
    name: Annotated[str, Field(min_length=1, strict=True)] = Field(description="REQUIRED. Fully-qualified name for the multi-vector index. Format: {extractor}_{version}_{output} (e.g., 'hybrid_extractor_v1_multi'). Must be unique across namespace.")
    description: Annotated[str, Field(min_length=10, strict=True)] = Field(description="REQUIRED. Human-readable description of the multi-vector index. Explain what vector types are included and their purposes. Describe use cases for this multi-vector configuration.")
    vectors: Dict[str, VectorIndex] = Field(description="REQUIRED. Dictionary mapping vector output names to their VectorIndex configurations. Each key is a unique identifier for that vector type within this multi-index. Each value is a complete VectorIndex with its own dimensions, type, and inference service. Example keys: 'dense', 'sparse', 'primary', 'secondary'.")
    __properties: ClassVar[List[str]] = ["name", "description", "vectors"]

    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 MultiVectorIndex 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 vectors (dict)
        _field_dict = {}
        if self.vectors:
            for _key_vectors in self.vectors:
                if self.vectors[_key_vectors]:
                    _field_dict[_key_vectors] = self.vectors[_key_vectors].to_dict()
            _dict['vectors'] = _field_dict
        return _dict

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

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "description": obj.get("description"),
            "vectors": dict(
                (_k, VectorIndex.from_dict(_v))
                for _k, _v in obj["vectors"].items()
            )
            if obj.get("vectors") is not None
            else None
        })
        return _obj


