# 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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from mixpeek.models.clarification_option import ClarificationOption
from mixpeek.models.suitable_collection import SuitableCollection
from typing import Optional, Set
from typing_extensions import Self

class IntentClassification(BaseModel):
    """
    Result of intent detection analysis.  This model represents the agent's understanding of whether the user wants to: - Execute queries on existing data (execution mode) - Create new resources/infrastructure (setup mode) - Or if the request is ambiguous and needs clarification  Attributes:     intent: The detected intent (\"execution\", \"setup\", or \"ambiguous\")     confidence: Confidence score 0.0-1.0     reasoning: Explanation of why this intent was detected     suitable_collections: Existing collections that might fulfill the request     recommended_action: What the agent should do next     clarification_needed: Whether to ask user for clarification     clarification_options: Options to present if clarification needed     keywords_found: Keywords that influenced the classification
    """ # noqa: E501
    intent: Annotated[str, Field(strict=True)] = Field(description="Detected intent: 'execution', 'setup', or 'ambiguous'")
    confidence: Union[Annotated[float, Field(le=1.0, strict=True, ge=0.0)], Annotated[int, Field(le=1, strict=True, ge=0)]] = Field(description="Confidence in classification")
    reasoning: StrictStr = Field(description="Why this intent was detected")
    suitable_collections: Optional[List[SuitableCollection]] = Field(default=None, description="Existing collections that might help")
    recommended_action: StrictStr = Field(description="Next action to take (e.g., 'setup_pipeline', 'execute_retriever')")
    clarification_needed: StrictBool = Field(description="Whether to ask user for clarification")
    clarification_options: Optional[List[ClarificationOption]] = Field(default=None, description="Options for user if clarification needed")
    keywords_found: Optional[Dict[str, List[StrictStr]]] = Field(default=None, description="Keywords found (setup_keywords, execution_keywords, neutral_keywords)")
    __properties: ClassVar[List[str]] = ["intent", "confidence", "reasoning", "suitable_collections", "recommended_action", "clarification_needed", "clarification_options", "keywords_found"]

    @field_validator('intent')
    def intent_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^(execution|setup|ambiguous)$", value):
            raise ValueError(r"must validate the regular expression /^(execution|setup|ambiguous)$/")
        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 IntentClassification 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 suitable_collections (list)
        _items = []
        if self.suitable_collections:
            for _item_suitable_collections in self.suitable_collections:
                if _item_suitable_collections:
                    _items.append(_item_suitable_collections.to_dict())
            _dict['suitable_collections'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in clarification_options (list)
        _items = []
        if self.clarification_options:
            for _item_clarification_options in self.clarification_options:
                if _item_clarification_options:
                    _items.append(_item_clarification_options.to_dict())
            _dict['clarification_options'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "intent": obj.get("intent"),
            "confidence": obj.get("confidence"),
            "reasoning": obj.get("reasoning"),
            "suitable_collections": [SuitableCollection.from_dict(_item) for _item in obj["suitable_collections"]] if obj.get("suitable_collections") is not None else None,
            "recommended_action": obj.get("recommended_action"),
            "clarification_needed": obj.get("clarification_needed"),
            "clarification_options": [ClarificationOption.from_dict(_item) for _item in obj["clarification_options"]] if obj.get("clarification_options") is not None else None,
            "keywords_found": obj.get("keywords_found")
        })
        return _obj


