# coding: utf-8

"""
    dAIEDGE-DLT

    API documentation

    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
from typing import Any, ClassVar, Dict, List
from daiedge_middleware_client.models.accelerator import Accelerator
from daiedge_middleware_client.models.cost import Cost
from daiedge_middleware_client.models.cpu import CPU
from daiedge_middleware_client.models.memory import Memory
from daiedge_middleware_client.models.power import Power
from daiedge_middleware_client.models.storage import Storage
from typing import Optional, Set
from typing_extensions import Self

class HardwareSpec(BaseModel):
    """
    HardwareSpec
    """ # noqa: E501
    cost: Cost
    cpus: List[CPU]
    accelerators: List[Accelerator]
    memory: Memory
    storage: Storage
    power: Power
    __properties: ClassVar[List[str]] = ["cost", "cpus", "accelerators", "memory", "storage", "power"]

    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 HardwareSpec 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 cost
        if self.cost:
            _dict['cost'] = self.cost.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in cpus (list)
        _items = []
        if self.cpus:
            for _item_cpus in self.cpus:
                if _item_cpus:
                    _items.append(_item_cpus.to_dict())
            _dict['cpus'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in accelerators (list)
        _items = []
        if self.accelerators:
            for _item_accelerators in self.accelerators:
                if _item_accelerators:
                    _items.append(_item_accelerators.to_dict())
            _dict['accelerators'] = _items
        # override the default output from pydantic by calling `to_dict()` of memory
        if self.memory:
            _dict['memory'] = self.memory.to_dict()
        # override the default output from pydantic by calling `to_dict()` of storage
        if self.storage:
            _dict['storage'] = self.storage.to_dict()
        # override the default output from pydantic by calling `to_dict()` of power
        if self.power:
            _dict['power'] = self.power.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "cost": Cost.from_dict(obj["cost"]) if obj.get("cost") is not None else None,
            "cpus": [CPU.from_dict(_item) for _item in obj["cpus"]] if obj.get("cpus") is not None else None,
            "accelerators": [Accelerator.from_dict(_item) for _item in obj["accelerators"]] if obj.get("accelerators") is not None else None,
            "memory": Memory.from_dict(obj["memory"]) if obj.get("memory") is not None else None,
            "storage": Storage.from_dict(obj["storage"]) if obj.get("storage") is not None else None,
            "power": Power.from_dict(obj["power"]) if obj.get("power") is not None else None
        })
        return _obj


