# 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: 0.81.1
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.enrichment_input_mapping import EnrichmentInputMapping
from mixpeek.models.logical_operator_input import LogicalOperatorInput
from mixpeek.models.post_processing_phase import PostProcessingPhase
from mixpeek.models.write_back_field_mapping import WriteBackFieldMapping
from typing import Optional, Set
from typing_extensions import Self

class RetrieverEnrichmentConfigInput(BaseModel):
    """
    Configuration for attaching a retriever enrichment to a collection.  Retriever enrichments run a retriever pipeline on each document during post-processing and write selected result fields back to the document.  Attributes:     retriever_id: ID of the retriever to execute     input_mappings: How to map document fields to retriever inputs     write_back_fields: Which result fields to write back to the document     execution_phase: Which post-processing phase to run in (default: RETRIEVER_ENRICHMENT)     priority: Priority within the execution phase (higher = runs first)     scroll_filters: Optional filters to select which documents to enrich     enabled: Whether this enrichment is active
    """ # noqa: E501
    retriever_id: StrictStr = Field(description="ID of the retriever to execute")
    input_mappings: Annotated[List[EnrichmentInputMapping], Field(min_length=1)] = Field(description="Map document fields or constants to retriever input parameters")
    write_back_fields: Annotated[List[WriteBackFieldMapping], Field(min_length=1)] = Field(description="Which retriever result fields to write back to the document")
    execution_phase: Optional[PostProcessingPhase] = Field(default=None, description="Which phase this enrichment runs in. Default: RETRIEVER_ENRICHMENT (phase 4, after taxonomies, clusters, and alerts)")
    priority: Optional[Annotated[int, Field(le=1000, strict=True, ge=0)]] = Field(default=0, description="Priority within the execution phase (higher = runs first)")
    scroll_filters: Optional[LogicalOperatorInput] = Field(default=None, description="Optional filters to select which documents to enrich")
    enabled: Optional[StrictBool] = Field(default=True, description="Whether this enrichment is active")
    __properties: ClassVar[List[str]] = ["retriever_id", "input_mappings", "write_back_fields", "execution_phase", "priority", "scroll_filters", "enabled"]

    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 RetrieverEnrichmentConfigInput 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 input_mappings (list)
        _items = []
        if self.input_mappings:
            for _item_input_mappings in self.input_mappings:
                if _item_input_mappings:
                    _items.append(_item_input_mappings.to_dict())
            _dict['input_mappings'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in write_back_fields (list)
        _items = []
        if self.write_back_fields:
            for _item_write_back_fields in self.write_back_fields:
                if _item_write_back_fields:
                    _items.append(_item_write_back_fields.to_dict())
            _dict['write_back_fields'] = _items
        # override the default output from pydantic by calling `to_dict()` of scroll_filters
        if self.scroll_filters:
            _dict['scroll_filters'] = self.scroll_filters.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of RetrieverEnrichmentConfigInput 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"),
            "input_mappings": [EnrichmentInputMapping.from_dict(_item) for _item in obj["input_mappings"]] if obj.get("input_mappings") is not None else None,
            "write_back_fields": [WriteBackFieldMapping.from_dict(_item) for _item in obj["write_back_fields"]] if obj.get("write_back_fields") is not None else None,
            "execution_phase": obj.get("execution_phase"),
            "priority": obj.get("priority") if obj.get("priority") is not None else 0,
            "scroll_filters": LogicalOperatorInput.from_dict(obj["scroll_filters"]) if obj.get("scroll_filters") is not None else None,
            "enabled": obj.get("enabled") if obj.get("enabled") is not None else True
        })
        return _obj


