# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List
from mixpeek.models.compound_index_pattern import CompoundIndexPattern
from mixpeek.models.field_performance_metrics import FieldPerformanceMetrics
from mixpeek.models.field_query_metrics import FieldQueryMetrics
from mixpeek.models.index_recommendation import IndexRecommendation
from typing import Optional, Set
from typing_extensions import Self

class NamespaceSummaryResponse(BaseModel):
    """
    Comprehensive namespace analytics summary.
    """ # noqa: E501
    namespace_id: StrictStr = Field(description="Namespace ID analyzed")
    time_range_days: StrictInt = Field(description="Number of days analyzed")
    summary: Dict[str, Any] = Field(description="Summary statistics (total_fields_analyzed, high_priority_indexes, etc.)")
    recommendations: List[IndexRecommendation] = Field(description="Top index recommendations")
    most_queried_fields: List[FieldQueryMetrics] = Field(description="Most frequently queried fields")
    slowest_fields: List[FieldPerformanceMetrics] = Field(description="Fields with highest latency")
    compound_indexes: List[CompoundIndexPattern] = Field(description="Compound index opportunities")
    __properties: ClassVar[List[str]] = ["namespace_id", "time_range_days", "summary", "recommendations", "most_queried_fields", "slowest_fields", "compound_indexes"]

    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 NamespaceSummaryResponse 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 each item in recommendations (list)
        _items = []
        if self.recommendations:
            for _item_recommendations in self.recommendations:
                if _item_recommendations:
                    _items.append(_item_recommendations.to_dict())
            _dict['recommendations'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in most_queried_fields (list)
        _items = []
        if self.most_queried_fields:
            for _item_most_queried_fields in self.most_queried_fields:
                if _item_most_queried_fields:
                    _items.append(_item_most_queried_fields.to_dict())
            _dict['most_queried_fields'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in slowest_fields (list)
        _items = []
        if self.slowest_fields:
            for _item_slowest_fields in self.slowest_fields:
                if _item_slowest_fields:
                    _items.append(_item_slowest_fields.to_dict())
            _dict['slowest_fields'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in compound_indexes (list)
        _items = []
        if self.compound_indexes:
            for _item_compound_indexes in self.compound_indexes:
                if _item_compound_indexes:
                    _items.append(_item_compound_indexes.to_dict())
            _dict['compound_indexes'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of NamespaceSummaryResponse 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"),
            "time_range_days": obj.get("time_range_days"),
            "summary": obj.get("summary"),
            "recommendations": [IndexRecommendation.from_dict(_item) for _item in obj["recommendations"]] if obj.get("recommendations") is not None else None,
            "most_queried_fields": [FieldQueryMetrics.from_dict(_item) for _item in obj["most_queried_fields"]] if obj.get("most_queried_fields") is not None else None,
            "slowest_fields": [FieldPerformanceMetrics.from_dict(_item) for _item in obj["slowest_fields"]] if obj.get("slowest_fields") is not None else None,
            "compound_indexes": [CompoundIndexPattern.from_dict(_item) for _item in obj["compound_indexes"]] if obj.get("compound_indexes") is not None else None
        })
        return _obj


