# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from mixpeek.models.input_mapping import InputMapping
from mixpeek.models.source_collection_input import SourceCollectionInput
from mixpeek.models.step_analytics_config_input import StepAnalyticsConfigInput
from typing import Optional, Set
from typing_extensions import Self

class FlatTaxonomyConfigInput(BaseModel):
    """
    Configuration for a *flat* taxonomy - single source collection with one retriever.
    """ # noqa: E501
    taxonomy_type: Optional[StrictStr] = Field(default='flat', description="Discriminator identifying this as a flat taxonomy.")
    retriever_id: StrictStr = Field(description="The retriever to use for matching against the source collection.")
    input_mappings: List[InputMapping] = Field(description="Input mappings defining how to construct retriever inputs.")
    source_collection: SourceCollectionInput = Field(description="The single source collection for this flat taxonomy.")
    step_analytics: Optional[StepAnalyticsConfigInput] = Field(default=None, description="Optional configuration for step transition analytics. Enables tracking how documents progress through taxonomy labels over time (e.g., email thread progression from 'inquiry' to 'closed_won'). If not provided, only basic assignment events are logged.")
    __properties: ClassVar[List[str]] = ["taxonomy_type", "retriever_id", "input_mappings", "source_collection", "step_analytics"]

    @field_validator('taxonomy_type')
    def taxonomy_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['flat']):
            raise ValueError("must be one of enum values ('flat')")
        return value

    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 FlatTaxonomyConfigInput 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 source_collection
        if self.source_collection:
            _dict['source_collection'] = self.source_collection.to_dict()
        # override the default output from pydantic by calling `to_dict()` of step_analytics
        if self.step_analytics:
            _dict['step_analytics'] = self.step_analytics.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "taxonomy_type": obj.get("taxonomy_type") if obj.get("taxonomy_type") is not None else 'flat',
            "retriever_id": obj.get("retriever_id"),
            "input_mappings": [InputMapping.from_dict(_item) for _item in obj["input_mappings"]] if obj.get("input_mappings") is not None else None,
            "source_collection": SourceCollectionInput.from_dict(obj["source_collection"]) if obj.get("source_collection") is not None else None,
            "step_analytics": StepAnalyticsConfigInput.from_dict(obj["step_analytics"]) if obj.get("step_analytics") is not None else None
        })
        return _obj


