# 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 mixpeek.models.logical_operator_input import LogicalOperatorInput
from mixpeek.models.sort_option import SortOption
from typing import Optional, Set
from typing_extensions import Self

class ListInteractionsRequest(BaseModel):
    """
    Request for listing interactions with filters.  Supports both simple field filters (for common queries) and advanced LogicalOperator filters (for complex analytics). This hybrid approach follows the same pattern as the Tasks module.  Common Queries (Simple Fields):     - Filter by execution: {\"execution_id\": \"exec_abc\"}     - Filter by session: {\"session_id\": \"sess_xyz\"}     - Filter by user: {\"user_id\": \"user_123\"}  Advanced Queries (LogicalOperator):     - Range queries: {\"filters\": {\"position\": {\"lte\": 5}}}     - Complex logic: {\"filters\": {\"AND\": [...]}}     - Time ranges: {\"filters\": {\"created_at\": {\"gte\": \"2025-01-01\"}}}
    """ # noqa: E501
    execution_id: Optional[StrictStr] = Field(default=None, description="Filter by retriever execution ID. Most common query: find all interactions from a specific search execution. Example: 'exec_abc123'")
    retriever_id: Optional[StrictStr] = Field(default=None, description="Filter by retriever ID. Compare performance across different retriever configurations. Example: 'ret_product_search_v2'")
    session_id: Optional[StrictStr] = Field(default=None, description="Filter by session ID. Track user journey across multiple searches within a session. Example: 'sess_xyz789'")
    user_id: Optional[StrictStr] = Field(default=None, description="Filter by user ID. Analyze behavior of specific users for personalization insights. Example: 'user_456'")
    feature_id: Optional[StrictStr] = Field(default=None, description="Filter by feature/document ID. Find all interactions with a specific document across all searches. Example: 'doc_abc123'")
    interaction_type: Optional[StrictStr] = Field(default=None, description="Filter by interaction type. Use to find specific behaviors like clicks, purchases, or feedback. Example: 'click', 'positive_feedback'")
    filters: Optional[LogicalOperatorInput] = Field(default=None, description="Advanced filters using LogicalOperator for complex analytics queries. Supports shorthand syntax and complex AND/OR/NOT logic. Use this for: range queries, complex conditions, metadata filtering. Examples:   - Position range: {'position': {'lte': 5}}   - Time range: {'timestamp': {'gte': '2025-01-01'}}   - Complex: {'AND': [{'field': 'position', 'operator': 'lte', 'value': 5},                       {'field': 'interaction_type', 'operator': 'in', 'value': ['click', 'purchase']}]} See LogicalOperator documentation for full syntax.")
    sort: Optional[SortOption] = Field(default=None, description="Sort options for ordering results. Default: timestamp descending (newest first). Examples:   - Sort by timestamp: {'field': 'timestamp', 'direction': 'desc'}   - Sort by position: {'field': 'position', 'direction': 'asc'}")
    search: Optional[StrictStr] = Field(default=None, description="Full-text search across metadata fields. NOT REQUIRED. Use to search interaction metadata content.")
    __properties: ClassVar[List[str]] = ["execution_id", "retriever_id", "session_id", "user_id", "feature_id", "interaction_type", "filters", "sort", "search"]

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

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

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

        _obj = cls.model_validate({
            "execution_id": obj.get("execution_id"),
            "retriever_id": obj.get("retriever_id"),
            "session_id": obj.get("session_id"),
            "user_id": obj.get("user_id"),
            "feature_id": obj.get("feature_id"),
            "interaction_type": obj.get("interaction_type"),
            "filters": LogicalOperatorInput.from_dict(obj["filters"]) if obj.get("filters") is not None else None,
            "sort": SortOption.from_dict(obj["sort"]) if obj.get("sort") is not None else None,
            "search": obj.get("search")
        })
        return _obj


