# 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
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.field_schema import FieldSchema
from mixpeek.models.payload_schema_type import PayloadSchemaType
from typing import Optional, Set
from typing_extensions import Self

class PayloadIndexConfigOutput(BaseModel):
    """
    Configuration for a payload index.  Defines the structure and behavior of a payload field index in Qdrant collections. Payload indexes enable efficient filtering and searching on document metadata.  Protected Indexes:     System-managed indexes (is_protected=True) cannot be modified or deleted by users.     These are essential for Mixpeek's internal operations:     - internal_id: Tenant isolation     - namespace_id: Namespace scoping     - collection_id, document_id: Document lineage     - bucket_id, object_id, root_object_id, root_bucket_id, source_object_id: Object lineage     - created_at, updated_at: Timestamps  Use Cases:     - Create custom metadata indexes for efficient filtering     - Configure full-text search on text fields     - Set up geospatial queries on location data     - Enable range queries on numeric fields  Requirements:     - field_name: REQUIRED - Must be unique within the namespace     - type: REQUIRED - Must match PayloadSchemaType enum     - field_schema: OPTIONAL - Auto-generated from type if not provided     - is_protected: OPTIONAL - Defaults to False (user-managed index)
    """ # noqa: E501
    field_name: Annotated[str, Field(min_length=1, strict=True, max_length=255)] = Field(description="Name of the payload field to index. Must be unique within the namespace. Use dot notation for nested fields (e.g., 'metadata.title'). Cannot use protected system field names when is_protected=False.")
    type: PayloadSchemaType = Field(description="Data type of the indexed field. Determines query capabilities and storage optimization. TEXT: Full-text search. KEYWORD: Exact matching, filtering. INTEGER/FLOAT: Range queries, sorting. DATETIME: Temporal queries. GEO: Geospatial queries. BOOL: Boolean filtering. UUID: Unique identifier matching.")
    field_schema: Optional[FieldSchema] = None
    is_protected: Optional[StrictBool] = Field(default=False, description="Whether this index is system-managed and cannot be modified by users. Protected indexes (is_protected=True) are created automatically by Mixpeek and are essential for internal operations like tenant isolation, lineage tracking, and document management. Users cannot create, modify, or delete protected indexes. User-created indexes always have is_protected=False.")
    __properties: ClassVar[List[str]] = ["field_name", "type", "field_schema", "is_protected"]

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

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

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

        _obj = cls.model_validate({
            "field_name": obj.get("field_name"),
            "type": obj.get("type"),
            "field_schema": FieldSchema.from_dict(obj["field_schema"]) if obj.get("field_schema") is not None else None,
            "is_protected": obj.get("is_protected") if obj.get("is_protected") is not None else False
        })
        return _obj


