# coding: utf-8

"""
    Amalgam Index API

    Amalgam Index (Amgix). Open-Source Hybrid Search System

    The version of the OpenAPI document: 1.1.0
    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, StrictBool, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class VectorConfig(BaseModel):
    """
    Configuration for a vector generation method.  This model defines how vectors should be generated for a specific field or set of fields. Different vector types have different requirements and behaviors.
    """ # noqa: E501
    name: StrictStr = Field(description="Unique name for this vector configuration")
    type: StrictStr = Field(description="Type of vector (dense_model, sparse_model, full_text, trigrams, whitespace, wmtr, dense_custom, sparse_custom)")
    model: Optional[Annotated[str, Field(strict=True, max_length=210)]] = Field(default=None, description="Model name for transformer-based vectors (max 210 characters, e.g., 'sentence-transformers/all-MiniLM-L6-v2'). Used for document indexing.")
    revision: Optional[Annotated[str, Field(strict=True, max_length=210)]] = Field(default=None, description="Optional model revision (max 210 characters, branch/tag/commit) for specific model version. Used for document indexing.")
    query_model: Optional[Annotated[str, Field(strict=True, max_length=210)]] = Field(default=None, description="Optional model name for query vectorization (max 210 characters). If not specified, uses 'model' for both documents and queries.")
    query_revision: Optional[Annotated[str, Field(strict=True, max_length=210)]] = Field(default=None, description="Optional model revision for query vectorization (max 210 characters). If not specified, uses 'revision' for both documents and queries.")
    dimensions: Optional[StrictInt] = Field(default=None, description="Dimensions for the vector. Required for dense_custom vectors. For dense_model vectors, auto-detected if not specified.")
    top_k: Optional[StrictInt] = Field(default=128, description="Number of top-scoring terms to keep for sparse vectors. Used by sparse_model, full_text, trigrams, whitespace, wmtr, and sparse_custom vectors. Ignored by dense vectors.")
    wmtr_word_weight: Optional[Annotated[int, Field(le=100, strict=True, ge=0)]] = Field(default=80, description="Percentage of WMTR top_k allocated to word weights.")
    index_fields: Optional[List[StrictStr]] = Field(default=None, description="List of fields to index with this vector (name, description, content). Defaults to ['content'] if not specified.")
    language_default_code: Optional[StrictStr] = Field(default='en', description="Two-letter ISO 639-1 language code for language-based vector types (e.g., 'en', 'es', 'fr')")
    language_detect: Optional[StrictBool] = Field(default=False, description="Whether to automatically detect language for language-based vector types")
    language_confidence: Optional[Union[StrictFloat, StrictInt]] = Field(default=0.9, description="Minimum confidence threshold for language detection. If detection confidence is below this value, language_default_code will be used instead.")
    normalization: Optional[StrictBool] = Field(default=None, description="Whether to normalize vectors. Only supported for dense vectors. Sparse vectors do not support normalization.")
    dense_distance: Optional[StrictStr] = Field(default='cosine', description="Distance metric for dense vectors (cosine, dot, euclid). Defaults to cosine.")
    keep_case: Optional[StrictBool] = Field(default=False, description="Whether to keep original case for text preprocessing. Only applies to model-based vectors (dense_model, sparse_model). Defaults to False (lowercase).")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["name", "type", "model", "revision", "query_model", "query_revision", "dimensions", "top_k", "wmtr_word_weight", "index_fields", "language_default_code", "language_detect", "language_confidence", "normalization", "dense_distance", "keep_case"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['dense_model', 'sparse_model', 'full_text', 'trigrams', 'whitespace', 'wmtr', 'keyword', 'dense_custom', 'sparse_custom']):
            raise ValueError("must be one of enum values ('dense_model', 'sparse_model', 'full_text', 'trigrams', 'whitespace', 'wmtr', 'keyword', 'dense_custom', 'sparse_custom')")
        return value

    @field_validator('index_fields')
    def index_fields_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        for i in value:
            if i not in set(['name', 'description', 'content']):
                raise ValueError("each list item must be one of ('name', 'description', 'content')")
        return value

    @field_validator('dense_distance')
    def dense_distance_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['cosine', 'dot', 'euclid']):
            raise ValueError("must be one of enum values ('cosine', 'dot', 'euclid')")
        return value

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=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"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of VectorConfig 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.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of VectorConfig 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"),
            "type": obj.get("type"),
            "model": obj.get("model"),
            "revision": obj.get("revision"),
            "query_model": obj.get("query_model"),
            "query_revision": obj.get("query_revision"),
            "dimensions": obj.get("dimensions"),
            "top_k": obj.get("top_k") if obj.get("top_k") is not None else 128,
            "wmtr_word_weight": obj.get("wmtr_word_weight") if obj.get("wmtr_word_weight") is not None else 80,
            "index_fields": obj.get("index_fields"),
            "language_default_code": obj.get("language_default_code") if obj.get("language_default_code") is not None else 'en',
            "language_detect": obj.get("language_detect") if obj.get("language_detect") is not None else False,
            "language_confidence": obj.get("language_confidence") if obj.get("language_confidence") is not None else 0.9,
            "normalization": obj.get("normalization"),
            "dense_distance": obj.get("dense_distance") if obj.get("dense_distance") is not None else 'cosine',
            "keep_case": obj.get("keep_case") if obj.get("keep_case") is not None else False
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


