# coding: utf-8

"""
    InductivaWebAPI

    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from inductiva.client.models.dynamic_disk_resize_config import DynamicDiskResizeConfig
from inductiva.client.models.machine_group_type import MachineGroupType
from typing import Optional, Set
from typing_extensions import Self


class RegisterVMGroupRequest(BaseModel):
    """
    RegisterVMGroupRequest
    """

  # noqa: E501
    machine_type: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    provider_id: Optional[StrictStr] = 'GCP'
    threads_per_core: Optional[StrictInt] = 2
    disk_size_gb: Optional[StrictInt] = 10
    max_idle_time: Optional[Union[StrictFloat, StrictInt]] = None
    auto_terminate_ts: Optional[datetime] = None
    dynamic_disk_resize_config: Optional[DynamicDiskResizeConfig] = None
    custom_vm_image: Optional[StrictStr] = None
    num_vms: Optional[StrictInt] = None
    min_vms: Optional[StrictInt] = None
    max_vms: Optional[StrictInt] = None
    type: Optional[MachineGroupType] = None
    is_elastic: Optional[StrictBool] = False
    spot: Optional[StrictBool] = False
    cpu_cores_logical: Optional[StrictInt] = None
    cpu_cores_physical: Optional[StrictInt] = None
    zone: Optional[StrictStr] = None
    gpu_count: Optional[StrictInt] = None
    gpu_name: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = [
        "machine_type", "name", "provider_id", "threads_per_core",
        "disk_size_gb", "max_idle_time", "auto_terminate_ts",
        "dynamic_disk_resize_config", "custom_vm_image", "num_vms", "min_vms",
        "max_vms", "type", "is_elastic", "spot", "cpu_cores_logical",
        "cpu_cores_physical", "zone", "gpu_count", "gpu_name"
    ]

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

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of RegisterVMGroupRequest 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"),
            "name":
                obj.get("name"),
            "provider_id":
                obj.get("provider_id")
                if obj.get("provider_id") is not None else 'GCP',
            "threads_per_core":
                obj.get("threads_per_core")
                if obj.get("threads_per_core") is not None else 2,
            "disk_size_gb":
                obj.get("disk_size_gb")
                if obj.get("disk_size_gb") is not None else 10,
            "max_idle_time":
                obj.get("max_idle_time"),
            "auto_terminate_ts":
                obj.get("auto_terminate_ts"),
            "dynamic_disk_resize_config":
                DynamicDiskResizeConfig.from_dict(
                    obj["dynamic_disk_resize_config"])
                if obj.get("dynamic_disk_resize_config") is not None else None,
            "custom_vm_image":
                obj.get("custom_vm_image"),
            "num_vms":
                obj.get("num_vms"),
            "min_vms":
                obj.get("min_vms"),
            "max_vms":
                obj.get("max_vms"),
            "type":
                obj.get("type"),
            "is_elastic":
                obj.get("is_elastic")
                if obj.get("is_elastic") is not None else False,
            "spot":
                obj.get("spot") if obj.get("spot") is not None else False,
            "cpu_cores_logical":
                obj.get("cpu_cores_logical"),
            "cpu_cores_physical":
                obj.get("cpu_cores_physical"),
            "zone":
                obj.get("zone"),
            "gpu_count":
                obj.get("gpu_count"),
            "gpu_name":
                obj.get("gpu_name")
        })
        return _obj
