# 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 typing_extensions import Annotated
from mixpeek.models.budget_limits import BudgetLimits
from mixpeek.models.display_config_input import DisplayConfigInput
from mixpeek.models.retriever_input_schema_field_input import RetrieverInputSchemaFieldInput
from mixpeek.models.stage_config import StageConfig
from typing import Optional, Set
from typing_extensions import Self

class CloneRetrieverRequest(BaseModel):
    """
    Request to clone a retriever with optional modifications.  **Purpose:** Cloning creates a NEW retriever (with new ID) based on an existing one, allowing you to make changes that aren't allowed via PATCH (stages, input_schema, collections). This is the recommended way to iterate on retriever designs.  **Clone vs Template vs Version:** - **Clone**: Copy THIS retriever and modify it (for iteration/fixes) - **Template**: Create retriever from a reusable pattern (for new projects) - **Version**: (Not implemented) - Use clone instead  **Use Cases:** - Fix a typo in a stage name without losing execution history - Add/remove stages while keeping the original intact - Change collections while preserving the original retriever - Test modifications before replacing production retriever - Create variants (e.g., \"strict\" vs \"relaxed\" versions)  **All fields are OPTIONAL:** - Omit a field to keep the original value - Provide a field to override the original value - retriever_name is REQUIRED (clones must have unique names)
    """ # noqa: E501
    retriever_name: Annotated[str, Field(min_length=1, strict=True)] = Field(description="REQUIRED. Name for the cloned retriever. Must be unique and different from the source retriever.")
    description: Optional[StrictStr] = Field(default=None, description="OPTIONAL. Description override. If omitted, copies from source retriever.")
    collection_identifiers: Optional[List[StrictStr]] = Field(default=None, description="OPTIONAL. Override target collections. If omitted, copies from source retriever. This allows you to apply the same retriever logic to different collections.")
    stages: Optional[List[StageConfig]] = Field(default=None, description="OPTIONAL. Override stage configurations. If omitted, copies from source retriever. This is where you'd fix typos, add stages, or tweak parameters.")
    input_schema: Optional[Dict[str, RetrieverInputSchemaFieldInput]] = Field(default=None, description="OPTIONAL. Override input schema. If omitted, copies from source retriever.")
    budget_limits: Optional[BudgetLimits] = Field(default=None, description="OPTIONAL. Override budget limits. If omitted, copies from source retriever.")
    tags: Optional[List[StrictStr]] = Field(default=None, description="OPTIONAL. Override tags. If omitted, copies from source retriever.")
    display_config: Optional[DisplayConfigInput] = Field(default=None, description="OPTIONAL. Override display configuration. If omitted, copies from source retriever.")
    __properties: ClassVar[List[str]] = ["retriever_name", "description", "collection_identifiers", "stages", "input_schema", "budget_limits", "tags", "display_config"]

    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 CloneRetrieverRequest 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 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 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 budget_limits
        if self.budget_limits:
            _dict['budget_limits'] = self.budget_limits.to_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 CloneRetrieverRequest 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": [StageConfig.from_dict(_item) for _item in obj["stages"]] if obj.get("stages") is not None else None,
            "input_schema": dict(
                (_k, RetrieverInputSchemaFieldInput.from_dict(_v))
                for _k, _v in obj["input_schema"].items()
            )
            if obj.get("input_schema") is not None
            else None,
            "budget_limits": BudgetLimits.from_dict(obj["budget_limits"]) if obj.get("budget_limits") is not None else None,
            "tags": obj.get("tags"),
            "display_config": DisplayConfigInput.from_dict(obj["display_config"]) if obj.get("display_config") is not None else None
        })
        return _obj


