# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from mixpeek.models.agent_config import AgentConfig
from mixpeek.models.session_stats import SessionStats
from mixpeek.models.session_status import SessionStatus
from typing import Optional, Set
from typing_extensions import Self

class GetSessionResponse(BaseModel):
    """
    Response for retrieving session metadata.  Attributes:     session_id: Session identifier     namespace_id: Namespace identifier     internal_id: Organization internal ID     user_id: Optional user identifier     session_name: Auto-generated session name (null until first message)     agent_config: Agent configuration     user_memory: User memory/preferences     status: Session status     message_count: Total messages in session     stats: Session statistics     created_at: Creation timestamp     updated_at: Last update timestamp     last_activity_at: Last activity timestamp     expires_at: Expiration timestamp  Example:     ```python     response = GetSessionResponse(         session_id=\"ses_abc123\",         namespace_id=\"ns_xyz789\",         internal_id=\"int_abc123\",         session_name=\"Video search for ML tutorials\",         agent_config=AgentConfig(...),         status=\"active\",         message_count=10,         stats=SessionStats(...)     )     ```
    """ # noqa: E501
    session_id: StrictStr = Field(description="Session identifier")
    namespace_id: StrictStr = Field(description="Namespace identifier")
    internal_id: StrictStr = Field(description="Organization internal ID")
    user_id: Optional[StrictStr] = Field(default=None, description="User identifier")
    session_name: Optional[StrictStr] = Field(default=None, description="Auto-generated session name based on first conversation")
    agent_config: AgentConfig = Field(description="Agent configuration")
    user_memory: Optional[Dict[str, Any]] = Field(default=None, description="User memory/preferences")
    status: SessionStatus = Field(description="Session status")
    message_count: StrictInt = Field(description="Total messages in session")
    stats: SessionStats = Field(description="Session statistics")
    created_at: datetime = Field(description="Creation timestamp")
    updated_at: datetime = Field(description="Last update timestamp")
    last_activity_at: datetime = Field(description="Last activity timestamp")
    expires_at: datetime = Field(description="Expiration timestamp")
    __properties: ClassVar[List[str]] = ["session_id", "namespace_id", "internal_id", "user_id", "session_name", "agent_config", "user_memory", "status", "message_count", "stats", "created_at", "updated_at", "last_activity_at", "expires_at"]

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

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

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

        _obj = cls.model_validate({
            "session_id": obj.get("session_id"),
            "namespace_id": obj.get("namespace_id"),
            "internal_id": obj.get("internal_id"),
            "user_id": obj.get("user_id"),
            "session_name": obj.get("session_name"),
            "agent_config": AgentConfig.from_dict(obj["agent_config"]) if obj.get("agent_config") is not None else None,
            "user_memory": obj.get("user_memory"),
            "status": obj.get("status"),
            "message_count": obj.get("message_count"),
            "stats": SessionStats.from_dict(obj["stats"]) if obj.get("stats") is not None else None,
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "last_activity_at": obj.get("last_activity_at"),
            "expires_at": obj.get("expires_at")
        })
        return _obj


