# 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.hierarchical_enrichment_style import HierarchicalEnrichmentStyle
from mixpeek.models.logical_operator_input import LogicalOperatorInput
from mixpeek.models.taxonomy_execution_mode import TaxonomyExecutionMode
from typing import Optional, Set
from typing_extensions import Self

class TaxonomyApplicationConfigInput(BaseModel):
    """
    Configuration block that attaches a taxonomy to a collection.  Supports execution phase ordering for unified post-processing with taxonomies, clusters, and alerts.
    """ # noqa: E501
    taxonomy_id: StrictStr = Field(description="ID of the `TaxonomyModel` to execute.")
    execution_mode: Optional[TaxonomyExecutionMode] = Field(default=None, description="Execution mode for taxonomy enrichment. Materializes results during ingestion.")
    target_collection_id: Optional[StrictStr] = Field(default=None, description="Optional collection to persist results into when `execution_mode` is 'materialize'. If omitted, the source collection is updated in-place.")
    scroll_filters: Optional[LogicalOperatorInput] = Field(default=None, description="Additional filters applied when scrolling the source collection before enrichment.")
    execution_phase: Optional[Annotated[int, Field(le=3, strict=True, ge=1)]] = Field(default=1, description="Which phase this taxonomy runs in. Default: 1 (TAXONOMY phase, runs first). Valid values: 1=TAXONOMY, 2=CLUSTER, 3=ALERT. Lower phases run earlier.")
    priority: Optional[Annotated[int, Field(le=1000, strict=True, ge=0)]] = Field(default=0, description="Priority within the execution phase (higher = runs first)")
    hierarchical_enrichment_style: Optional[HierarchicalEnrichmentStyle] = Field(default=None, description="For hierarchical taxonomies, controls how enrichment fields are structured. 'full_chain': Each tier writes to tier-prefixed fields (tier1_id, tier2_id, etc.). 'best_match': Only deepest match stored (category_id, category_name, path[]). 'combined' (default): Both full chain AND best match summary fields.")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["taxonomy_id", "execution_mode", "target_collection_id", "scroll_filters", "execution_phase", "priority", "hierarchical_enrichment_style"]

    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 TaxonomyApplicationConfigInput 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.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # 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()
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

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

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

        _obj = cls.model_validate({
            "taxonomy_id": obj.get("taxonomy_id"),
            "execution_mode": obj.get("execution_mode"),
            "target_collection_id": obj.get("target_collection_id"),
            "scroll_filters": LogicalOperatorInput.from_dict(obj["scroll_filters"]) if obj.get("scroll_filters") is not None else None,
            "execution_phase": obj.get("execution_phase") if obj.get("execution_phase") is not None else 1,
            "priority": obj.get("priority") if obj.get("priority") is not None else 0,
            "hierarchical_enrichment_style": obj.get("hierarchical_enrichment_style")
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


