# coding: utf-8

"""
    JupyterHub

    The REST API for JupyterHub

    The version of the OpenAPI document: 4.0.2
    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 typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictBool, StrictStr, field_validator
from pydantic import Field
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class Server(BaseModel):
    """
    Server
    """ # noqa: E501
    name: Optional[StrictStr] = Field(default=None, description="The server's name. The user's default server has an empty name ('')")
    ready: Optional[StrictBool] = Field(default=None, description="Whether the server is ready for traffic. Will always be false when any transition is pending. ")
    stopped: Optional[StrictBool] = Field(default=None, description="Whether the server is stopped. Added in JupyterHub 3.0, and only useful when using the `?include_stopped_servers` request parameter. Now that stopped servers may be included (since JupyterHub 3.0), this is the simplest way to select stopped servers. Always equivalent to `not (ready or pending)`. ")
    pending: Optional[StrictStr] = Field(default=None, description="The currently pending action, if any. A server is not ready if an action is pending. ")
    url: Optional[StrictStr] = Field(default=None, description="The URL where the server can be accessed (typically /user/:name/:server.name/). ")
    progress_url: Optional[StrictStr] = Field(default=None, description="The URL for an event-stream to retrieve events during a spawn. ")
    started: Optional[datetime] = Field(default=None, description="UTC timestamp when the server was last started.")
    last_activity: Optional[datetime] = Field(default=None, description="UTC timestamp last-seen activity on this server.")
    state: Optional[Dict[str, Any]] = Field(default=None, description="Arbitrary internal state from this server's spawner. Only available on the hub's users list or get-user-by-name method, and only with admin:users:server_state scope. None otherwise.")
    user_options: Optional[Dict[str, Any]] = Field(default=None, description="User specified options for the user's spawned instance of a single-user server.")
    __properties: ClassVar[List[str]] = ["name", "ready", "stopped", "pending", "url", "progress_url", "started", "last_activity", "state", "user_options"]

    @field_validator('pending')
    def pending_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in ('spawn', 'stop'):
            raise ValueError("must be one of enum values ('spawn', 'stop')")
        return value

    model_config = {
        "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) -> Self:
        """Create an instance of Server 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
            },
            exclude_none=True,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict) -> Self:
        """Create an instance of Server from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "ready": obj.get("ready"),
            "stopped": obj.get("stopped"),
            "pending": obj.get("pending"),
            "url": obj.get("url"),
            "progress_url": obj.get("progress_url"),
            "started": obj.get("started"),
            "last_activity": obj.get("last_activity"),
            "state": obj.get("state"),
            "user_options": obj.get("user_options")
        })
        return _obj


