# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from mixpeek.models.base_feature_extractor_model_output import BaseFeatureExtractorModelOutput
from mixpeek.models.namespace_infrastructure import NamespaceInfrastructure
from mixpeek.models.payload_index_config_output import PayloadIndexConfigOutput
from typing import Optional, Set
from typing_extensions import Self

class NamespaceModel(BaseModel):
    """
    Namespace model.
    """ # noqa: E501
    namespace_id: Optional[StrictStr] = Field(default=None, description="Unique identifier for the namespace")
    namespace_name: StrictStr = Field(description="Name of the namespace")
    infrastructure: Optional[NamespaceInfrastructure] = Field(default=None, description="Infrastructure configuration for the namespace (Ray, Qdrant).")
    cluster_id: Optional[StrictStr] = Field(default=None, description="Infrastructure cluster ID for this namespace (Enterprise only). When set, this namespace uses dedicated Anyscale/Ray + Qdrant cluster. If None, uses shared infrastructure or organization-level infrastructure. Format: iclstr_xxx")
    description: Optional[StrictStr] = Field(default=None, description="Description of the namespace")
    feature_extractors: Optional[List[BaseFeatureExtractorModelOutput]] = Field(default=None, description="List of feature extractors configured for this namespace")
    payload_indexes: Optional[List[PayloadIndexConfigOutput]] = Field(default=None, description="Custom payload indexes configured for this namespace")
    document_count: Optional[StrictInt] = Field(default=None, description="Total number of documents in this namespace (from Qdrant collection)")
    bucket_count: Optional[StrictInt] = Field(default=None, description="Total number of buckets in this namespace")
    collection_count: Optional[StrictInt] = Field(default=None, description="Total number of collections in this namespace")
    object_count: Optional[StrictInt] = Field(default=None, description="Total number of objects across all buckets in this namespace")
    auto_create_indexes: Optional[StrictBool] = Field(default=False, description="Enable automatic creation of Qdrant payload indexes based on filter usage patterns. When enabled, the system tracks which fields are most frequently filtered (>100 queries/24h) and automatically creates indexes to improve query performance. Background task runs every 6 hours. Expected performance improvement: 50-90% latency reduction for filtered queries.")
    vector_inference_map: Optional[Dict[str, StrictStr]] = Field(default=None, description="Mapping of vector index names to inference service names. Built at namespace creation based on extractor configurations. Used by feature search to determine correct inference service for queries. Example: {'image_extractor_v1_embedding': 'google_siglip_base_v1'}")
    created_at: Optional[datetime] = Field(default=None, description="When the namespace was created")
    updated_at: Optional[datetime] = Field(default=None, description="When the namespace was last updated")
    __properties: ClassVar[List[str]] = ["namespace_id", "namespace_name", "infrastructure", "cluster_id", "description", "feature_extractors", "payload_indexes", "document_count", "bucket_count", "collection_count", "object_count", "auto_create_indexes", "vector_inference_map", "created_at", "updated_at"]

    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 NamespaceModel 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 infrastructure
        if self.infrastructure:
            _dict['infrastructure'] = self.infrastructure.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in feature_extractors (list)
        _items = []
        if self.feature_extractors:
            for _item_feature_extractors in self.feature_extractors:
                if _item_feature_extractors:
                    _items.append(_item_feature_extractors.to_dict())
            _dict['feature_extractors'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in payload_indexes (list)
        _items = []
        if self.payload_indexes:
            for _item_payload_indexes in self.payload_indexes:
                if _item_payload_indexes:
                    _items.append(_item_payload_indexes.to_dict())
            _dict['payload_indexes'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "namespace_id": obj.get("namespace_id"),
            "namespace_name": obj.get("namespace_name"),
            "infrastructure": NamespaceInfrastructure.from_dict(obj["infrastructure"]) if obj.get("infrastructure") is not None else None,
            "cluster_id": obj.get("cluster_id"),
            "description": obj.get("description"),
            "feature_extractors": [BaseFeatureExtractorModelOutput.from_dict(_item) for _item in obj["feature_extractors"]] if obj.get("feature_extractors") is not None else None,
            "payload_indexes": [PayloadIndexConfigOutput.from_dict(_item) for _item in obj["payload_indexes"]] if obj.get("payload_indexes") is not None else None,
            "document_count": obj.get("document_count"),
            "bucket_count": obj.get("bucket_count"),
            "collection_count": obj.get("collection_count"),
            "object_count": obj.get("object_count"),
            "auto_create_indexes": obj.get("auto_create_indexes") if obj.get("auto_create_indexes") is not None else False,
            "vector_inference_map": obj.get("vector_inference_map"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


