# coding: utf-8

"""
    Rancher Solution API

    Simplify enterprise-grade Kubernetes cluster operations and management with Rancher on Bare Metal Cloud. Deploy Kubernetes clusters using a few API calls.<br> <br> <span class='pnap-api-knowledge-base-link'> Knowledge base articles to help you can be found <a href='https://phoenixnap.com/kb/rancher-bmc-integration-kubernetes' target='_blank'>here</a> </span><br> <br> <b>All URLs are relative to (https://api.phoenixnap.com/solutions/rancher/v1beta)</b> 

    The version of the OpenAPI document: 0.1
    Contact: support@phoenixnap.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, StrictStr
from pydantic import Field
from typing_extensions import Annotated
from pnap_rancher_solution_api.models.node_pool import NodePool
from pnap_rancher_solution_api.models.rancher_cluster_config import RancherClusterConfig
from pnap_rancher_solution_api.models.rancher_server_metadata import RancherServerMetadata
from pnap_rancher_solution_api.models.workload_cluster_config import WorkloadClusterConfig
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class Cluster(BaseModel):
    """
    Cluster details.
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="(Read-only) The Cluster identifier.")
    name: Optional[StrictStr] = Field(default=None, description="Cluster name. This field is autogenerated if not provided.")
    description: Optional[StrictStr] = Field(default=None, description="Cluster description.")
    location: StrictStr = Field(description="Deployment location. Cannot be changed once a cluster is created. Currently this field should be set to `PHX`, `ASH`, `SGP`, `NLD`, `CHI`, `SEA` or `AUS`.")
    initial_cluster_version: Optional[StrictStr] = Field(default=None, description="(Read-only) The Rancher version that was installed on the cluster during the first creation process.", alias="initialClusterVersion")
    node_pools: Optional[Annotated[List[NodePool], Field(min_length=1, max_length=1)]] = Field(default=None, description="The node pools associated with the cluster.", alias="nodePools")
    configuration: Optional[RancherClusterConfig] = None
    metadata: Optional[RancherServerMetadata] = None
    workload_configuration: Optional[WorkloadClusterConfig] = Field(default=None, alias="workloadConfiguration")
    status_description: Optional[StrictStr] = Field(default=None, description="(Read-Only) The cluster status", alias="statusDescription")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["id", "name", "description", "location", "initialClusterVersion", "nodePools", "configuration", "metadata", "workloadConfiguration", "statusDescription"]

    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 Cluster 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
                "id",
                "initial_cluster_version",
                "metadata",
                "status_description",
                "additional_properties",
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in node_pools (list)
        _items = []
        if self.node_pools:
            for _item in self.node_pools:
                if _item:
                    _items.append(_item.to_dict())
            _dict['nodePools'] = _items
        # override the default output from pydantic by calling `to_dict()` of configuration
        if self.configuration:
            _dict['configuration'] = self.configuration.to_dict()
        # override the default output from pydantic by calling `to_dict()` of metadata
        if self.metadata:
            _dict['metadata'] = self.metadata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of workload_configuration
        if self.workload_configuration:
            _dict['workloadConfiguration'] = self.workload_configuration.to_dict()
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "location": obj.get("location"),
            "initialClusterVersion": obj.get("initialClusterVersion"),
            "nodePools": [NodePool.from_dict(_item) for _item in obj.get("nodePools")] if obj.get("nodePools") is not None else None,
            "configuration": RancherClusterConfig.from_dict(obj.get("configuration")) if obj.get("configuration") is not None else None,
            "metadata": RancherServerMetadata.from_dict(obj.get("metadata")) if obj.get("metadata") is not None else None,
            "workloadConfiguration": WorkloadClusterConfig.from_dict(obj.get("workloadConfiguration")) if obj.get("workloadConfiguration") is not None else None,
            "statusDescription": obj.get("statusDescription")
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


