# 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, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.attribute_based_config import AttributeBasedConfig
from mixpeek.models.cluster_type import ClusterType
from mixpeek.models.llm_labeling_input import LLMLabelingInput
from mixpeek.models.logical_operator_input import LogicalOperatorInput
from mixpeek.models.source_enrichment_config import SourceEnrichmentConfig
from mixpeek.models.vector_based_config_input import VectorBasedConfigInput
from typing import Optional, Set
from typing_extensions import Self

class CreateClusterRequest(BaseModel):
    """
    Create a clustering job for one or more collections.
    """ # noqa: E501
    collection_ids: Annotated[List[StrictStr], Field(min_length=1)] = Field(description="Collections to cluster together")
    cluster_name: Optional[StrictStr] = Field(default=None, description="Optional human-friendly name for the clustering job")
    cluster_type: Optional[ClusterType] = Field(default=None, description="Vector or attribute clustering")
    vector_config: Optional[VectorBasedConfigInput] = Field(default=None, description="Required when cluster_type is 'vector'")
    attribute_config: Optional[AttributeBasedConfig] = Field(default=None, description="Required when cluster_type is 'attribute'")
    filters: Optional[LogicalOperatorInput] = Field(default=None, description="Optional filters to pre-filter documents before clustering (same format as list documents). Applied during Qdrant scroll before parquet export. Useful for clustering subsets like: status='active', category='electronics', etc.")
    llm_labeling: Optional[LLMLabelingInput] = Field(default=None, description="Optional configuration for LLM-based cluster labeling. When provided with enabled=True, clusters will have semantic labels generated by LLM instead of generic labels like 'Cluster 0'. When not provided or enabled=False, uses fallback labels.")
    enrich_source_collection: Optional[StrictBool] = Field(default=False, description="If True, cluster results are written back to source collection(s) in-place instead of creating new output collections. Documents will be enriched with cluster_id, cluster_label, distance_to_centroid, and optionally other metadata. Similar to taxonomy enrichment pattern.")
    source_enrichment_config: Optional[SourceEnrichmentConfig] = Field(default=None, description="Configuration for source collection enrichment (only used if enrich_source_collection=True). Controls which fields are added to source documents and field naming conventions.")
    __properties: ClassVar[List[str]] = ["collection_ids", "cluster_name", "cluster_type", "vector_config", "attribute_config", "filters", "llm_labeling", "enrich_source_collection", "source_enrichment_config"]

    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 CreateClusterRequest 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 vector_config
        if self.vector_config:
            _dict['vector_config'] = self.vector_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of attribute_config
        if self.attribute_config:
            _dict['attribute_config'] = self.attribute_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of filters
        if self.filters:
            _dict['filters'] = self.filters.to_dict()
        # override the default output from pydantic by calling `to_dict()` of llm_labeling
        if self.llm_labeling:
            _dict['llm_labeling'] = self.llm_labeling.to_dict()
        # override the default output from pydantic by calling `to_dict()` of source_enrichment_config
        if self.source_enrichment_config:
            _dict['source_enrichment_config'] = self.source_enrichment_config.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "collection_ids": obj.get("collection_ids"),
            "cluster_name": obj.get("cluster_name"),
            "cluster_type": obj.get("cluster_type"),
            "vector_config": VectorBasedConfigInput.from_dict(obj["vector_config"]) if obj.get("vector_config") is not None else None,
            "attribute_config": AttributeBasedConfig.from_dict(obj["attribute_config"]) if obj.get("attribute_config") is not None else None,
            "filters": LogicalOperatorInput.from_dict(obj["filters"]) if obj.get("filters") is not None else None,
            "llm_labeling": LLMLabelingInput.from_dict(obj["llm_labeling"]) if obj.get("llm_labeling") is not None else None,
            "enrich_source_collection": obj.get("enrich_source_collection") if obj.get("enrich_source_collection") is not None else False,
            "source_enrichment_config": SourceEnrichmentConfig.from_dict(obj["source_enrichment_config"]) if obj.get("source_enrichment_config") is not None else None
        })
        return _obj


