# coding: utf-8

"""
    IONOS DBaaS MongoDB REST API

    With IONOS Cloud Database as a Service, you have the ability to quickly set up and manage a MongoDB database. You can also delete clusters, manage backups and users via the API.  MongoDB is an open source, cross-platform, document-oriented database program. Classified as a NoSQL database program, it uses JSON-like documents with optional schemas.  The MongoDB API allows you to create additional database clusters or modify existing ones. Both tools, the Data Center Designer (DCD) and the API use the same concepts consistently and are well suited for smooth and intuitive use. 

    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, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from ionoscloud_dbaas_mongo.models.backup_properties import BackupProperties
from ionoscloud_dbaas_mongo.models.bi_connector_properties import BiConnectorProperties
from ionoscloud_dbaas_mongo.models.connection import Connection
from ionoscloud_dbaas_mongo.models.create_restore_request import CreateRestoreRequest
from ionoscloud_dbaas_mongo.models.maintenance_window import MaintenanceWindow
from ionoscloud_dbaas_mongo.models.storage_type import StorageType
from typing import Optional, Set
from typing_extensions import Self

class CreateClusterProperties(BaseModel):
    """
    The properties with all data needed to create a new MongoDB cluster. 
    """ # noqa: E501
    type: Optional[StrictStr] = Field(default=None, description="The cluster type, either `replicaset` or `sharded-cluster`. ")
    template_id: Optional[StrictStr] = Field(default=None, description="The unique ID of the template, which specifies the number of cores, storage size, and memory. You cannot downgrade to a smaller template or minor edition (e.g. from business to playground). To get a list of all templates to confirm the changes use the /templates endpoint. ", alias="templateID")
    mongo_db_version: Optional[StrictStr] = Field(default=None, description="The MongoDB version of your cluster.", alias="mongoDBVersion")
    instances: Optional[StrictInt] = Field(default=None, description="The total number of instances in the cluster (one primary and n-1 secondaries). ")
    shards: Optional[StrictInt] = Field(default=None, description="The total number of shards in the cluster. ")
    connections: Optional[Annotated[List[Connection], Field(min_length=1, max_length=1)]] = None
    location: Optional[StrictStr] = Field(default=None, description="The physical location where the cluster will be created. This is the location where all your instances will be located. This property is immutable. ")
    backup: Optional[BackupProperties] = None
    display_name: Optional[StrictStr] = Field(default=None, description="The name of your cluster.", alias="displayName")
    maintenance_window: Optional[MaintenanceWindow] = Field(default=None, alias="maintenanceWindow")
    bi_connector: Optional[BiConnectorProperties] = Field(default=None, alias="biConnector")
    from_backup: Optional[CreateRestoreRequest] = Field(default=None, alias="fromBackup")
    edition: Optional[StrictStr] = Field(default=None, description="The cluster edition.")
    cores: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=None, description="The number of CPU cores per instance.")
    ram: Optional[Annotated[int, Field(multiple_of=1024, strict=True, ge=2048)]] = Field(default=None, description="The amount of memory per instance in megabytes. Has to be a multiple of 1024.")
    storage_size: Optional[Annotated[int, Field(le=2097152, strict=True, ge=2048)]] = Field(default=None, description="The amount of storage per instance in megabytes.", alias="storageSize")
    storage_type: Optional[StorageType] = Field(default=None, alias="storageType")
    __properties: ClassVar[List[str]] = ["type", "templateID", "mongoDBVersion", "instances", "shards", "connections", "location", "backup", "displayName", "maintenanceWindow", "biConnector", "fromBackup", "edition", "cores", "ram", "storageSize", "storageType"]

    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 CreateClusterProperties 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 each item in connections (list)
        _items = []
        if self.connections:
            for _item_connections in self.connections:
                if _item_connections:
                    _items.append(_item_connections.to_dict())
            _dict['connections'] = _items
        # override the default output from pydantic by calling `to_dict()` of backup
        if self.backup:
            _dict['backup'] = self.backup.to_dict()
        # override the default output from pydantic by calling `to_dict()` of maintenance_window
        if self.maintenance_window:
            _dict['maintenanceWindow'] = self.maintenance_window.to_dict()
        # override the default output from pydantic by calling `to_dict()` of bi_connector
        if self.bi_connector:
            _dict['biConnector'] = self.bi_connector.to_dict()
        # override the default output from pydantic by calling `to_dict()` of from_backup
        if self.from_backup:
            _dict['fromBackup'] = self.from_backup.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "type": obj.get("type"),
            "templateID": obj.get("templateID"),
            "mongoDBVersion": obj.get("mongoDBVersion"),
            "instances": obj.get("instances"),
            "shards": obj.get("shards"),
            "connections": [Connection.from_dict(_item) for _item in obj["connections"]] if obj.get("connections") is not None else None,
            "location": obj.get("location"),
            "backup": BackupProperties.from_dict(obj["backup"]) if obj.get("backup") is not None else None,
            "displayName": obj.get("displayName"),
            "maintenanceWindow": MaintenanceWindow.from_dict(obj["maintenanceWindow"]) if obj.get("maintenanceWindow") is not None else None,
            "biConnector": BiConnectorProperties.from_dict(obj["biConnector"]) if obj.get("biConnector") is not None else None,
            "fromBackup": CreateRestoreRequest.from_dict(obj["fromBackup"]) if obj.get("fromBackup") is not None else None,
            "edition": obj.get("edition"),
            "cores": obj.get("cores"),
            "ram": obj.get("ram"),
            "storageSize": obj.get("storageSize"),
            "storageType": obj.get("storageType")
        })
        return _obj


