# coding: utf-8

"""
    Cyberwave API

    Cyberwave platform REST API. Use 'Bearer YOUR_TOKEN' for authentication.

    The version of the OpenAPI document: 1.0.0
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from cyberwave.rest.models.admin_session_schema import AdminSessionSchema
from typing import Optional, Set
from typing_extensions import Self

class AdminLabOverviewSchema(BaseModel):
    """
    AdminLabOverviewSchema
    """ # noqa: E501
    environment_name: StrictStr
    environment_uuid: StrictStr
    active_session: Optional[AdminSessionSchema] = None
    queue: List[AdminSessionSchema]
    recent_sessions: List[AdminSessionSchema]
    stats: Dict[str, StrictInt]
    __properties: ClassVar[List[str]] = ["environment_name", "environment_uuid", "active_session", "queue", "recent_sessions", "stats"]

    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 AdminLabOverviewSchema 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 active_session
        if self.active_session:
            _dict['active_session'] = self.active_session.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in queue (list)
        _items = []
        if self.queue:
            for _item_queue in self.queue:
                if _item_queue:
                    _items.append(_item_queue.to_dict())
            _dict['queue'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in recent_sessions (list)
        _items = []
        if self.recent_sessions:
            for _item_recent_sessions in self.recent_sessions:
                if _item_recent_sessions:
                    _items.append(_item_recent_sessions.to_dict())
            _dict['recent_sessions'] = _items
        # set to None if active_session (nullable) is None
        # and model_fields_set contains the field
        if self.active_session is None and "active_session" in self.model_fields_set:
            _dict['active_session'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "environment_name": obj.get("environment_name"),
            "environment_uuid": obj.get("environment_uuid"),
            "active_session": AdminSessionSchema.from_dict(obj["active_session"]) if obj.get("active_session") is not None else None,
            "queue": [AdminSessionSchema.from_dict(_item) for _item in obj["queue"]] if obj.get("queue") is not None else None,
            "recent_sessions": [AdminSessionSchema.from_dict(_item) for _item in obj["recent_sessions"]] if obj.get("recent_sessions") is not None else None,
            "stats": obj.get("stats")
        })
        return _obj


