# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.response_shape2 import ResponseShape2
from mixpeek.models.text_split_strategy import TextSplitStrategy
from typing import Optional, Set
from typing_extensions import Self

class TextExtractorParams(BaseModel):
    """
    Parameters for the text extractor.  The text extractor generates dense vector embeddings optimized for semantic similarity search. It uses the E5-Large multilingual model to convert text into 1024-dimensional vectors.
    """ # noqa: E501
    extractor_type: Optional[StrictStr] = Field(default='text_extractor', description="Discriminator field for parameter type identification.")
    split_by: Optional[TextSplitStrategy] = Field(default=None, description="Strategy for splitting text into multiple documents.")
    chunk_size: Optional[Annotated[int, Field(le=10000, strict=True, ge=1)]] = Field(default=1000, description="Target size for each chunk.")
    chunk_overlap: Optional[Annotated[int, Field(le=5000, strict=True, ge=0)]] = Field(default=0, description="Number of units to overlap between consecutive chunks.")
    response_shape: Optional[ResponseShape2] = None
    llm_provider: Optional[StrictStr] = Field(default=None, description="LLM provider for structured extraction (openai, google, anthropic).")
    llm_model: Optional[StrictStr] = Field(default=None, description="Specific LLM model for structured extraction.")
    llm_api_key: Optional[StrictStr] = Field(default=None, description="API key for LLM operations (BYOK - Bring Your Own Key). Supports: - Direct key: 'sk-proj-abc123...' - Secret reference: '{{SECRET.openai_api_key}}'  When using secret reference, the key is loaded from your organization's secrets vault at runtime. Store secrets via POST /v1/organizations/secrets.  If not provided, uses Mixpeek's default API keys.")
    __properties: ClassVar[List[str]] = ["extractor_type", "split_by", "chunk_size", "chunk_overlap", "response_shape", "llm_provider", "llm_model", "llm_api_key"]

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

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

    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 TextExtractorParams 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 response_shape
        if self.response_shape:
            _dict['response_shape'] = self.response_shape.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "extractor_type": obj.get("extractor_type") if obj.get("extractor_type") is not None else 'text_extractor',
            "split_by": obj.get("split_by"),
            "chunk_size": obj.get("chunk_size") if obj.get("chunk_size") is not None else 1000,
            "chunk_overlap": obj.get("chunk_overlap") if obj.get("chunk_overlap") is not None else 0,
            "response_shape": ResponseShape2.from_dict(obj["response_shape"]) if obj.get("response_shape") is not None else None,
            "llm_provider": obj.get("llm_provider"),
            "llm_model": obj.get("llm_model"),
            "llm_api_key": obj.get("llm_api_key")
        })
        return _obj


