Source code for openapi_client.models.app_usage

# coding: utf-8

"""
    Amorphic Data Platform

    Amorphic Data Platform - API Definition documentation

    The version of the OpenAPI document: 0.3.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
from typing import Any, ClassVar, Dict, List, Optional
from openapi_client.models.license import License
from openapi_client.models.time_period import TimePeriod
from openapi_client.models.usage import Usage
from openapi_client.models.usage_by_service import UsageByService
from openapi_client.models.usage_pattern_object import UsagePatternObject
from typing import Optional, Set
from typing_extensions import Self

[docs] class AppUsage(BaseModel): """ AppUsage """ # noqa: E501 time_period: Optional[TimePeriod] = Field(default=None, alias="TimePeriod") current_usage: Optional[Usage] = Field(default=None, alias="CurrentUsage") estimated_usage: Optional[Usage] = Field(default=None, alias="EstimatedUsage") usage_by_service: Optional[List[UsageByService]] = Field(default=None, alias="UsageByService") usage_pattern: Optional[List[UsagePatternObject]] = Field(default=None, alias="UsagePattern") license: Optional[License] = Field(default=None, alias="License") discount: Optional[Usage] = Field(default=None, alias="Discount") total_bill: Optional[Usage] = Field(default=None, alias="TotalBill") __properties: ClassVar[List[str]] = ["TimePeriod", "CurrentUsage", "EstimatedUsage", "UsageByService", "UsagePattern", "License", "Discount", "TotalBill"] model_config = ConfigDict( populate_by_name=True, validate_assignment=True, protected_namespaces=(), )
[docs] def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True))
[docs] 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())
[docs] @classmethod def from_json(cls, json_str: str) -> Optional[Self]: """Create an instance of AppUsage from a JSON string""" return cls.from_dict(json.loads(json_str))
[docs] 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 time_period if self.time_period: _dict['TimePeriod'] = self.time_period.to_dict() # override the default output from pydantic by calling `to_dict()` of current_usage if self.current_usage: _dict['CurrentUsage'] = self.current_usage.to_dict() # override the default output from pydantic by calling `to_dict()` of estimated_usage if self.estimated_usage: _dict['EstimatedUsage'] = self.estimated_usage.to_dict() # override the default output from pydantic by calling `to_dict()` of each item in usage_by_service (list) _items = [] if self.usage_by_service: for _item_usage_by_service in self.usage_by_service: if _item_usage_by_service: _items.append(_item_usage_by_service.to_dict()) _dict['UsageByService'] = _items # override the default output from pydantic by calling `to_dict()` of each item in usage_pattern (list) _items = [] if self.usage_pattern: for _item_usage_pattern in self.usage_pattern: if _item_usage_pattern: _items.append(_item_usage_pattern.to_dict()) _dict['UsagePattern'] = _items # override the default output from pydantic by calling `to_dict()` of license if self.license: _dict['License'] = self.license.to_dict() # override the default output from pydantic by calling `to_dict()` of discount if self.discount: _dict['Discount'] = self.discount.to_dict() # override the default output from pydantic by calling `to_dict()` of total_bill if self.total_bill: _dict['TotalBill'] = self.total_bill.to_dict() return _dict
[docs] @classmethod def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: """Create an instance of AppUsage from a dict""" if obj is None: return None if not isinstance(obj, dict): return cls.model_validate(obj) _obj = cls.model_validate({ "TimePeriod": TimePeriod.from_dict(obj["TimePeriod"]) if obj.get("TimePeriod") is not None else None, "CurrentUsage": Usage.from_dict(obj["CurrentUsage"]) if obj.get("CurrentUsage") is not None else None, "EstimatedUsage": Usage.from_dict(obj["EstimatedUsage"]) if obj.get("EstimatedUsage") is not None else None, "UsageByService": [UsageByService.from_dict(_item) for _item in obj["UsageByService"]] if obj.get("UsageByService") is not None else None, "UsagePattern": [UsagePatternObject.from_dict(_item) for _item in obj["UsagePattern"]] if obj.get("UsagePattern") is not None else None, "License": License.from_dict(obj["License"]) if obj.get("License") is not None else None, "Discount": Usage.from_dict(obj["Discount"]) if obj.get("Discount") is not None else None, "TotalBill": Usage.from_dict(obj["TotalBill"]) if obj.get("TotalBill") is not None else None }) return _obj