# 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.providers import Providers
from typing import Optional, Set
from typing_extensions import Self


class MachineTypeWithSpotPrice(BaseModel):
    """
    MachineTypeWithSpotPrice
    """

  # noqa: E501
    machine_type: StrictStr
    num_vcpus: StrictInt
    ram_gb: Union[StrictFloat, StrictInt]
    price: Union[StrictFloat, StrictInt]
    provider_id: Optional[Providers] = None
    threads_per_core: Optional[StrictInt] = None
    spot: Optional[StrictBool] = None
    region: Optional[StrictStr] = None
    zone: Optional[StrictStr] = None
    num_gpus: Optional[StrictInt] = None
    gpu_id: Optional[StrictStr] = None
    gpu_name: Optional[StrictStr] = None
    spot_price: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = [
        "machine_type", "num_vcpus", "ram_gb", "price", "provider_id",
        "threads_per_core", "spot", "region", "zone", "num_gpus", "gpu_id",
        "gpu_name", "spot_price"
    ]

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "machine_type": obj.get("machine_type"),
            "num_vcpus": obj.get("num_vcpus"),
            "ram_gb": obj.get("ram_gb"),
            "price": obj.get("price"),
            "provider_id": obj.get("provider_id"),
            "threads_per_core": obj.get("threads_per_core"),
            "spot": obj.get("spot"),
            "region": obj.get("region"),
            "zone": obj.get("zone"),
            "num_gpus": obj.get("num_gpus"),
            "gpu_id": obj.get("gpu_id"),
            "gpu_name": obj.get("gpu_name"),
            "spot_price": obj.get("spot_price")
        })
        return _obj
