# coding: utf-8

"""
    Slurm Rest API

    API to access and control Slurm.

    The version of the OpenAPI document: 0.0.38
    Contact: sales@schedmd.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 typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictBool, StrictInt
from pydantic import Field
from openapi_client.models.v0038_diag_rpcm import V0038DiagRpcm
from openapi_client.models.v0038_diag_rpcu import V0038DiagRpcu
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class V0038DiagStatistics(BaseModel):
    """
    Slurm statistics
    """ # noqa: E501
    parts_packed: Optional[StrictInt] = Field(default=None, description="partition records packed")
    req_time: Optional[StrictInt] = Field(default=None, description="generation time")
    req_time_start: Optional[StrictInt] = Field(default=None, description="data since")
    server_thread_count: Optional[StrictInt] = Field(default=None, description="Server thread count")
    agent_queue_size: Optional[StrictInt] = Field(default=None, description="Agent queue size")
    agent_count: Optional[StrictInt] = Field(default=None, description="Agent count")
    agent_thread_count: Optional[StrictInt] = Field(default=None, description="Agent thread count")
    dbd_agent_queue_size: Optional[StrictInt] = Field(default=None, description="DBD Agent queue size")
    gettimeofday_latency: Optional[StrictInt] = Field(default=None, description="Latency for 1000 calls to gettimeofday()")
    schedule_cycle_max: Optional[StrictInt] = Field(default=None, description="Main Schedule max cycle")
    schedule_cycle_last: Optional[StrictInt] = Field(default=None, description="Main Schedule last cycle")
    schedule_cycle_total: Optional[StrictInt] = Field(default=None, description="Main Schedule cycle iterations")
    schedule_cycle_mean: Optional[StrictInt] = Field(default=None, description="Average time for Schedule Max cycle")
    schedule_cycle_mean_depth: Optional[StrictInt] = Field(default=None, description="Average depth for Schedule Max cycle")
    schedule_cycle_per_minute: Optional[StrictInt] = Field(default=None, description="Main Schedule Cycles per minute")
    schedule_queue_length: Optional[StrictInt] = Field(default=None, description="Main Schedule Last queue length")
    jobs_submitted: Optional[StrictInt] = Field(default=None, description="Job submitted")
    jobs_started: Optional[StrictInt] = Field(default=None, description="Job started")
    jobs_completed: Optional[StrictInt] = Field(default=None, description="Job completed")
    jobs_canceled: Optional[StrictInt] = Field(default=None, description="Job cancelled")
    jobs_failed: Optional[StrictInt] = Field(default=None, description="Job failed")
    jobs_pending: Optional[StrictInt] = Field(default=None, description="Job pending")
    jobs_running: Optional[StrictInt] = Field(default=None, description="Job running")
    job_states_ts: Optional[StrictInt] = Field(default=None, description="Job states timestamp")
    bf_backfilled_jobs: Optional[StrictInt] = Field(default=None, description="Total backfilled jobs (since last slurm start)")
    bf_last_backfilled_jobs: Optional[StrictInt] = Field(default=None, description="Total backfilled jobs (since last stats cycle start)")
    bf_backfilled_het_jobs: Optional[StrictInt] = Field(default=None, description="Total backfilled heterogeneous job components")
    bf_cycle_counter: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Total cycles")
    bf_cycle_mean: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Mean cycle")
    bf_cycle_max: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Max cycle time")
    bf_last_depth: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Last depth cycle")
    bf_last_depth_try: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Mean cycle (try sched)")
    bf_depth_mean: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Depth Mean")
    bf_depth_mean_try: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Depth Mean (try sched)")
    bf_cycle_last: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Last cycle time")
    bf_queue_len: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Last queue length")
    bf_queue_len_mean: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Mean queue length")
    bf_table_size: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Last table size")
    bf_table_size_mean: Optional[StrictInt] = Field(default=None, description="Backfill Schedule Mean table size")
    bf_when_last_cycle: Optional[StrictInt] = Field(default=None, description="Last cycle timestamp")
    bf_active: Optional[StrictBool] = Field(default=None, description="Backfill Schedule currently active")
    rpcs_by_message_type: Optional[List[V0038DiagRpcm]] = Field(default=None, description="Remote Procedure Call statistics by message type")
    rpcs_by_user: Optional[List[V0038DiagRpcu]] = Field(default=None, description="Remote Procedure Call statistics by user")
    __properties: ClassVar[List[str]] = ["parts_packed", "req_time", "req_time_start", "server_thread_count", "agent_queue_size", "agent_count", "agent_thread_count", "dbd_agent_queue_size", "gettimeofday_latency", "schedule_cycle_max", "schedule_cycle_last", "schedule_cycle_total", "schedule_cycle_mean", "schedule_cycle_mean_depth", "schedule_cycle_per_minute", "schedule_queue_length", "jobs_submitted", "jobs_started", "jobs_completed", "jobs_canceled", "jobs_failed", "jobs_pending", "jobs_running", "job_states_ts", "bf_backfilled_jobs", "bf_last_backfilled_jobs", "bf_backfilled_het_jobs", "bf_cycle_counter", "bf_cycle_mean", "bf_cycle_max", "bf_last_depth", "bf_last_depth_try", "bf_depth_mean", "bf_depth_mean_try", "bf_cycle_last", "bf_queue_len", "bf_queue_len_mean", "bf_table_size", "bf_table_size_mean", "bf_when_last_cycle", "bf_active", "rpcs_by_message_type", "rpcs_by_user"]

    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 V0038DiagStatistics 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,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in rpcs_by_message_type (list)
        _items = []
        if self.rpcs_by_message_type:
            for _item in self.rpcs_by_message_type:
                if _item:
                    _items.append(_item.to_dict())
            _dict['rpcs_by_message_type'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in rpcs_by_user (list)
        _items = []
        if self.rpcs_by_user:
            for _item in self.rpcs_by_user:
                if _item:
                    _items.append(_item.to_dict())
            _dict['rpcs_by_user'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "parts_packed": obj.get("parts_packed"),
            "req_time": obj.get("req_time"),
            "req_time_start": obj.get("req_time_start"),
            "server_thread_count": obj.get("server_thread_count"),
            "agent_queue_size": obj.get("agent_queue_size"),
            "agent_count": obj.get("agent_count"),
            "agent_thread_count": obj.get("agent_thread_count"),
            "dbd_agent_queue_size": obj.get("dbd_agent_queue_size"),
            "gettimeofday_latency": obj.get("gettimeofday_latency"),
            "schedule_cycle_max": obj.get("schedule_cycle_max"),
            "schedule_cycle_last": obj.get("schedule_cycle_last"),
            "schedule_cycle_total": obj.get("schedule_cycle_total"),
            "schedule_cycle_mean": obj.get("schedule_cycle_mean"),
            "schedule_cycle_mean_depth": obj.get("schedule_cycle_mean_depth"),
            "schedule_cycle_per_minute": obj.get("schedule_cycle_per_minute"),
            "schedule_queue_length": obj.get("schedule_queue_length"),
            "jobs_submitted": obj.get("jobs_submitted"),
            "jobs_started": obj.get("jobs_started"),
            "jobs_completed": obj.get("jobs_completed"),
            "jobs_canceled": obj.get("jobs_canceled"),
            "jobs_failed": obj.get("jobs_failed"),
            "jobs_pending": obj.get("jobs_pending"),
            "jobs_running": obj.get("jobs_running"),
            "job_states_ts": obj.get("job_states_ts"),
            "bf_backfilled_jobs": obj.get("bf_backfilled_jobs"),
            "bf_last_backfilled_jobs": obj.get("bf_last_backfilled_jobs"),
            "bf_backfilled_het_jobs": obj.get("bf_backfilled_het_jobs"),
            "bf_cycle_counter": obj.get("bf_cycle_counter"),
            "bf_cycle_mean": obj.get("bf_cycle_mean"),
            "bf_cycle_max": obj.get("bf_cycle_max"),
            "bf_last_depth": obj.get("bf_last_depth"),
            "bf_last_depth_try": obj.get("bf_last_depth_try"),
            "bf_depth_mean": obj.get("bf_depth_mean"),
            "bf_depth_mean_try": obj.get("bf_depth_mean_try"),
            "bf_cycle_last": obj.get("bf_cycle_last"),
            "bf_queue_len": obj.get("bf_queue_len"),
            "bf_queue_len_mean": obj.get("bf_queue_len_mean"),
            "bf_table_size": obj.get("bf_table_size"),
            "bf_table_size_mean": obj.get("bf_table_size_mean"),
            "bf_when_last_cycle": obj.get("bf_when_last_cycle"),
            "bf_active": obj.get("bf_active"),
            "rpcs_by_message_type": [V0038DiagRpcm.from_dict(_item) for _item in obj.get("rpcs_by_message_type")] if obj.get("rpcs_by_message_type") is not None else None,
            "rpcs_by_user": [V0038DiagRpcu.from_dict(_item) for _item in obj.get("rpcs_by_user")] if obj.get("rpcs_by_user") is not None else None
        })
        return _obj


