# coding: utf-8

"""
    STACKIT Cloud Foundry API

    API endpoints for managing STACKIT Cloud Foundry

    The version of the OpenAPI document: 1.0.0
    Contact: support@stackit.cloud
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501

from __future__ import annotations

import json
import pprint
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field
from typing_extensions import Annotated, Self


class QuotaApps(BaseModel):
    """
    QuotaApps
    """  # noqa: E501

    log_rate_limit_in_bytes_per_second: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(
        description="The value `null` means `unlimited`. ", alias="logRateLimitInBytesPerSecond"
    )
    per_app_tasks: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(
        description="The value `null` means `unlimited`. ", alias="perAppTasks"
    )
    per_process_memory_in_mb: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(
        description="The value `null` means `unlimited`. ", alias="perProcessMemoryInMb"
    )
    total_instances: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(
        description="The value `null` means `unlimited`. ", alias="totalInstances"
    )
    total_memory_in_mb: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(
        description="The value `null` means `unlimited`. ", alias="totalMemoryInMb"
    )
    __properties: ClassVar[List[str]] = [
        "logRateLimitInBytesPerSecond",
        "perAppTasks",
        "perProcessMemoryInMb",
        "totalInstances",
        "totalMemoryInMb",
    ]

    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 QuotaApps 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 log_rate_limit_in_bytes_per_second (nullable) is None
        # and model_fields_set contains the field
        if (
            self.log_rate_limit_in_bytes_per_second is None
            and "log_rate_limit_in_bytes_per_second" in self.model_fields_set
        ):
            _dict["logRateLimitInBytesPerSecond"] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "logRateLimitInBytesPerSecond": obj.get("logRateLimitInBytesPerSecond"),
                "perAppTasks": obj.get("perAppTasks"),
                "perProcessMemoryInMb": obj.get("perProcessMemoryInMb"),
                "totalInstances": obj.get("totalInstances"),
                "totalMemoryInMb": obj.get("totalMemoryInMb"),
            }
        )
        return _obj
