# 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.interaction_weights import InteractionWeights
from mixpeek.models.time_range_input import TimeRangeInput
from typing import Optional, Set
from typing_extensions import Self

class SessionFilterInput(BaseModel):
    """
    Criteria for selecting historical sessions to replay.
    """ # noqa: E501
    retriever_ids: Optional[List[StrictStr]] = Field(default=None, description="Filter to sessions from these retrievers.")
    taxonomy_node_ids: Optional[List[StrictStr]] = Field(default=None, description="Filter to sessions with these taxonomy classifications.")
    time_range: Optional[TimeRangeInput] = Field(default=None, description="Filter to sessions within this time window.")
    min_interactions: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=1, description="Minimum number of user interactions required.")
    interaction_types: Optional[List[StrictStr]] = Field(default=None, description="Filter to sessions with these interaction types (e.g., ['click', 'purchase']).")
    sample_strategy: Optional[StrictStr] = Field(default='random', description="How to sample sessions: 'random', 'recent', or 'stratified'.")
    interaction_weights: Optional[InteractionWeights] = Field(default=None, description="Custom weights for interaction types when computing relevance scores.")
    __properties: ClassVar[List[str]] = ["retriever_ids", "taxonomy_node_ids", "time_range", "min_interactions", "interaction_types", "sample_strategy", "interaction_weights"]

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

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

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

        _obj = cls.model_validate({
            "retriever_ids": obj.get("retriever_ids"),
            "taxonomy_node_ids": obj.get("taxonomy_node_ids"),
            "time_range": TimeRangeInput.from_dict(obj["time_range"]) if obj.get("time_range") is not None else None,
            "min_interactions": obj.get("min_interactions") if obj.get("min_interactions") is not None else 1,
            "interaction_types": obj.get("interaction_types"),
            "sample_strategy": obj.get("sample_strategy") if obj.get("sample_strategy") is not None else 'random',
            "interaction_weights": InteractionWeights.from_dict(obj["interaction_weights"]) if obj.get("interaction_weights") is not None else None
        })
        return _obj


