# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from mixpeek.models.display_config_output import DisplayConfigOutput
from mixpeek.models.retriever_input_schema_field_output import RetrieverInputSchemaFieldOutput
from typing import Optional, Set
from typing_extensions import Self

class PublicRetrieverTemplateResponse(BaseModel):
    """
    Response containing public retriever configuration as a reusable template.  This returns the retriever's configuration in a format that can be directly used in a CreateRetrieverRequest. Users can copy this config, modify it for their needs (e.g., change collection_identifiers), and create their own retriever.  Use Case:     1. Browse public retrievers to find patterns you like     2. GET /public/retrievers/{public_name}/template to get the config     3. Modify collection_identifiers and other fields as needed     4. POST /retrievers to create your own retriever with this config     5. Optionally POST /retrievers/{id}/publish to publish it similarly
    """ # noqa: E501
    retriever_name: StrictStr = Field(description="Original retriever name (you'll change this when creating your own). Provided as reference.")
    description: Optional[StrictStr] = Field(default=None, description="Original retriever description (you can use or modify this). Provides context about what this retriever does.")
    collection_identifiers: List[StrictStr] = Field(description="IMPORTANT: These are the original collections. You MUST replace these with your own collection identifiers when creating a retriever from this template.")
    stages: List[Dict[str, Any]] = Field(description="Pipeline stages configuration. You can use as-is or modify for your needs. This is the core retrieval logic.")
    input_schema: Dict[str, RetrieverInputSchemaFieldOutput] = Field(description="Input schema defining expected inputs. If you change the input field names, make sure to update references in stages (e.g., {{inputs.query}}).")
    budget_limits: Dict[str, Any] = Field(description="Budget limits for execution. You can adjust these based on your needs.")
    tags: Optional[List[StrictStr]] = Field(default=None, description="Original tags (optional, for reference)")
    display_config: Optional[DisplayConfigOutput] = Field(default=None, description="OPTIONAL: Display configuration used for the public interface. Include this if you plan to publish your retriever and want to use a similar UI design. Otherwise, you can omit it.")
    source_public_name: StrictStr = Field(description="Public name of the source retriever (for reference)")
    source_public_url: StrictStr = Field(description="Public URL of the source retriever (to view it in action)")
    feature_extractors: Optional[List[Dict[str, Any]]] = Field(default=None, description="Feature extractors from all collections used by this retriever. Each extractor includes: feature_extractor_name, version, params, input_mappings, collection_id, and collection_name for reference. Shows how each collection processes data into searchable features.")
    __properties: ClassVar[List[str]] = ["retriever_name", "description", "collection_identifiers", "stages", "input_schema", "budget_limits", "tags", "display_config", "source_public_name", "source_public_url", "feature_extractors"]

    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 PublicRetrieverTemplateResponse 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 value in input_schema (dict)
        _field_dict = {}
        if self.input_schema:
            for _key_input_schema in self.input_schema:
                if self.input_schema[_key_input_schema]:
                    _field_dict[_key_input_schema] = self.input_schema[_key_input_schema].to_dict()
            _dict['input_schema'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of display_config
        if self.display_config:
            _dict['display_config'] = self.display_config.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "retriever_name": obj.get("retriever_name"),
            "description": obj.get("description"),
            "collection_identifiers": obj.get("collection_identifiers"),
            "stages": obj.get("stages"),
            "input_schema": dict(
                (_k, RetrieverInputSchemaFieldOutput.from_dict(_v))
                for _k, _v in obj["input_schema"].items()
            )
            if obj.get("input_schema") is not None
            else None,
            "budget_limits": obj.get("budget_limits"),
            "tags": obj.get("tags"),
            "display_config": DisplayConfigOutput.from_dict(obj["display_config"]) if obj.get("display_config") is not None else None,
            "source_public_name": obj.get("source_public_name"),
            "source_public_url": obj.get("source_public_url"),
            "feature_extractors": obj.get("feature_extractors")
        })
        return _obj


