# 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
from pydantic import Field
from openapi_client.models.v0038_error import V0038Error
from openapi_client.models.v0038_meta import V0038Meta
from openapi_client.models.v0038_partition import V0038Partition
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class V0038PartitionsResponse(BaseModel):
    """
    V0038PartitionsResponse
    """ # noqa: E501
    meta: Optional[V0038Meta] = None
    errors: Optional[List[V0038Error]] = Field(default=None, description="slurm errors")
    partitions: Optional[List[V0038Partition]] = Field(default=None, description="partition info")
    __properties: ClassVar[List[str]] = ["meta", "errors", "partitions"]

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

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

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

        _obj = cls.model_validate({
            "meta": V0038Meta.from_dict(obj.get("meta")) if obj.get("meta") is not None else None,
            "errors": [V0038Error.from_dict(_item) for _item in obj.get("errors")] if obj.get("errors") is not None else None,
            "partitions": [V0038Partition.from_dict(_item) for _item in obj.get("partitions")] if obj.get("partitions") is not None else None
        })
        return _obj


