# coding: utf-8

"""
    Machine Catalogue

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 0.1.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, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from inductiva.machines_catalogue_client.models.gpu_architecture_info import GPUArchitectureInfo
from typing import Optional, Set
from typing_extensions import Self


class GPUSpecificationInfo(BaseModel):
    """
    Detailed GPU specification.  Contains comprehensive GPU hardware details including memory, compute performance, and advanced features.
    """ # noqa: E501
    gpu_id: StrictStr
    gpu_name: StrictStr
    vram_gb: StrictInt
    memory_type: Optional[StrictStr] = None
    memory_bandwidth_gbs: Optional[StrictInt] = None
    compute_tflops: Dict[str, Union[StrictFloat, StrictInt]]
    tdp_watts: Optional[StrictInt] = None
    transformer_engine: Optional[StrictBool] = False
    form_factor: Optional[StrictStr] = None
    mig_instances: Optional[StrictInt] = None
    nvlink_bandwidth_gbs: Optional[StrictInt] = None
    architecture: Optional[GPUArchitectureInfo] = None
    __properties: ClassVar[List[str]] = [
        "gpu_id", "gpu_name", "vram_gb", "memory_type", "memory_bandwidth_gbs",
        "compute_tflops", "tdp_watts", "transformer_engine", "form_factor",
        "mig_instances", "nvlink_bandwidth_gbs", "architecture"
    ]

    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 GPUSpecificationInfo 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 architecture
        if self.architecture:
            _dict['architecture'] = self.architecture.to_dict()
        # set to None if memory_type (nullable) is None
        # and model_fields_set contains the field
        if self.memory_type is None and "memory_type" in self.model_fields_set:
            _dict['memory_type'] = None

        # set to None if memory_bandwidth_gbs (nullable) is None
        # and model_fields_set contains the field
        if self.memory_bandwidth_gbs is None and "memory_bandwidth_gbs" in self.model_fields_set:
            _dict['memory_bandwidth_gbs'] = None

        # set to None if tdp_watts (nullable) is None
        # and model_fields_set contains the field
        if self.tdp_watts is None and "tdp_watts" in self.model_fields_set:
            _dict['tdp_watts'] = None

        # set to None if form_factor (nullable) is None
        # and model_fields_set contains the field
        if self.form_factor is None and "form_factor" in self.model_fields_set:
            _dict['form_factor'] = None

        # set to None if mig_instances (nullable) is None
        # and model_fields_set contains the field
        if self.mig_instances is None and "mig_instances" in self.model_fields_set:
            _dict['mig_instances'] = None

        # set to None if nvlink_bandwidth_gbs (nullable) is None
        # and model_fields_set contains the field
        if self.nvlink_bandwidth_gbs is None and "nvlink_bandwidth_gbs" in self.model_fields_set:
            _dict['nvlink_bandwidth_gbs'] = None

        # set to None if architecture (nullable) is None
        # and model_fields_set contains the field
        if self.architecture is None and "architecture" in self.model_fields_set:
            _dict['architecture'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "gpu_id":
                obj.get("gpu_id"),
            "gpu_name":
                obj.get("gpu_name"),
            "vram_gb":
                obj.get("vram_gb"),
            "memory_type":
                obj.get("memory_type"),
            "memory_bandwidth_gbs":
                obj.get("memory_bandwidth_gbs"),
            "compute_tflops":
                obj.get("compute_tflops"),
            "tdp_watts":
                obj.get("tdp_watts"),
            "transformer_engine":
                obj.get("transformer_engine")
                if obj.get("transformer_engine") is not None else False,
            "form_factor":
                obj.get("form_factor"),
            "mig_instances":
                obj.get("mig_instances"),
            "nvlink_bandwidth_gbs":
                obj.get("nvlink_bandwidth_gbs"),
            "architecture":
                GPUArchitectureInfo.from_dict(obj["architecture"])
                if obj.get("architecture") is not None else None
        })
        return _obj
