# 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.cache_config import CacheConfig
from mixpeek.models.collection_detail import CollectionDetail
from mixpeek.models.creator_info import CreatorInfo
from mixpeek.models.health_check import HealthCheck
from mixpeek.models.retriever_schema import RetrieverSchema
from mixpeek.models.retriever_status import RetrieverStatus
from mixpeek.models.revision_history_entry import RevisionHistoryEntry
from mixpeek.models.stage_instance_config import StageInstanceConfig
from mixpeek.models.usage_statistics import UsageStatistics
from typing import Optional, Set
from typing_extensions import Self

class RetrieverModelInput(BaseModel):
    """
    Retriever model.
    """ # noqa: E501
    retriever_id: Optional[StrictStr] = Field(default=None, description="Unique identifier for the retriever")
    retriever_name: StrictStr = Field(description="Name of the retriever")
    description: Optional[StrictStr] = Field(default=None, description="Description of the retriever")
    input_schema: RetrieverSchema = Field(description="Input schema for the retriever")
    collection_ids: List[StrictStr] = Field(description="List of collection IDs")
    stages: List[StageInstanceConfig] = Field(description="List of stage configurations")
    cache_config: Optional[CacheConfig] = Field(default=None, description="Cache configuration for this retriever. If not provided, caching is disabled.")
    created_at: Optional[datetime] = Field(default=None, description="When the retriever was created")
    updated_at: Optional[datetime] = Field(default=None, description="When the retriever was last modified")
    last_executed_at: Optional[datetime] = Field(default=None, description="When the retriever was last executed")
    enabled: Optional[StrictBool] = Field(default=True, description="Whether the retriever is enabled (can be toggled on/off)")
    status: Optional[RetrieverStatus] = Field(default=None, description="Current operational status")
    usage_stats: Optional[UsageStatistics] = Field(default=None, description="Usage and performance statistics")
    collections: Optional[List[CollectionDetail]] = Field(default=None, description="Expanded collection details with names and metadata")
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="Custom key-value metadata")
    tags: Optional[List[StrictStr]] = Field(default=None, description="Tags for organization and filtering")
    created_by: Optional[CreatorInfo] = Field(default=None, description="Information about who created this retriever")
    updated_by: Optional[CreatorInfo] = Field(default=None, description="Information about who last updated this retriever")
    version: Optional[StrictInt] = Field(default=1, description="Version number (increments on each update)")
    revision_history: Optional[List[RevisionHistoryEntry]] = Field(default=None, description="History of changes (optional, last N changes)")
    health: Optional[HealthCheck] = Field(default=None, description="Health status and diagnostics")
    __properties: ClassVar[List[str]] = ["retriever_id", "retriever_name", "description", "input_schema", "collection_ids", "stages", "cache_config", "created_at", "updated_at", "last_executed_at", "enabled", "status", "usage_stats", "collections", "metadata", "tags", "created_by", "updated_by", "version", "revision_history", "health"]

    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 RetrieverModelInput 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 input_schema
        if self.input_schema:
            _dict['input_schema'] = self.input_schema.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in stages (list)
        _items = []
        if self.stages:
            for _item_stages in self.stages:
                if _item_stages:
                    _items.append(_item_stages.to_dict())
            _dict['stages'] = _items
        # override the default output from pydantic by calling `to_dict()` of cache_config
        if self.cache_config:
            _dict['cache_config'] = self.cache_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of usage_stats
        if self.usage_stats:
            _dict['usage_stats'] = self.usage_stats.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in collections (list)
        _items = []
        if self.collections:
            for _item_collections in self.collections:
                if _item_collections:
                    _items.append(_item_collections.to_dict())
            _dict['collections'] = _items
        # override the default output from pydantic by calling `to_dict()` of created_by
        if self.created_by:
            _dict['created_by'] = self.created_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of updated_by
        if self.updated_by:
            _dict['updated_by'] = self.updated_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in revision_history (list)
        _items = []
        if self.revision_history:
            for _item_revision_history in self.revision_history:
                if _item_revision_history:
                    _items.append(_item_revision_history.to_dict())
            _dict['revision_history'] = _items
        # override the default output from pydantic by calling `to_dict()` of health
        if self.health:
            _dict['health'] = self.health.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "retriever_id": obj.get("retriever_id"),
            "retriever_name": obj.get("retriever_name"),
            "description": obj.get("description"),
            "input_schema": RetrieverSchema.from_dict(obj["input_schema"]) if obj.get("input_schema") is not None else None,
            "collection_ids": obj.get("collection_ids"),
            "stages": [StageInstanceConfig.from_dict(_item) for _item in obj["stages"]] if obj.get("stages") is not None else None,
            "cache_config": CacheConfig.from_dict(obj["cache_config"]) if obj.get("cache_config") is not None else None,
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "last_executed_at": obj.get("last_executed_at"),
            "enabled": obj.get("enabled") if obj.get("enabled") is not None else True,
            "status": obj.get("status"),
            "usage_stats": UsageStatistics.from_dict(obj["usage_stats"]) if obj.get("usage_stats") is not None else None,
            "collections": [CollectionDetail.from_dict(_item) for _item in obj["collections"]] if obj.get("collections") is not None else None,
            "metadata": obj.get("metadata"),
            "tags": obj.get("tags"),
            "created_by": CreatorInfo.from_dict(obj["created_by"]) if obj.get("created_by") is not None else None,
            "updated_by": CreatorInfo.from_dict(obj["updated_by"]) if obj.get("updated_by") is not None else None,
            "version": obj.get("version") if obj.get("version") is not None else 1,
            "revision_history": [RevisionHistoryEntry.from_dict(_item) for _item in obj["revision_history"]] if obj.get("revision_history") is not None else None,
            "health": HealthCheck.from_dict(obj["health"]) if obj.get("health") is not None else None
        })
        return _obj


