# coding: utf-8

"""
    Graphiant APIs

    Graphiant API documentation.

    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, StrictFloat, StrictInt
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from graphiant_sdk.models.v1_alarm_history_get200_response_history_inner_time import V1AlarmHistoryGet200ResponseHistoryInnerTime
from graphiant_sdk.models.v1_bwtracker_enterprise_summary_post200_response_bwusage_summary_bwusage_role_summary_inner import V1BwtrackerEnterpriseSummaryPost200ResponseBwusageSummaryBwusageRoleSummaryInner
from graphiant_sdk.models.v1_bwtracker_enterprise_summary_post200_response_bwusage_summary_bwusage_top_regions_inner import V1BwtrackerEnterpriseSummaryPost200ResponseBwusageSummaryBwusageTopRegionsInner
from typing import Optional, Set
from typing_extensions import Self

class V1BwtrackerEnterpriseSummaryPost200ResponseBwusageSummary(BaseModel):
    """
    V1BwtrackerEnterpriseSummaryPost200ResponseBwusageSummary
    """ # noqa: E501
    bwusage_role_summary: Optional[List[V1BwtrackerEnterpriseSummaryPost200ResponseBwusageSummaryBwusageRoleSummaryInner]] = Field(default=None, alias="bwusageRoleSummary")
    bwusage_top_regions: Optional[List[V1BwtrackerEnterpriseSummaryPost200ResponseBwusageSummaryBwusageTopRegionsInner]] = Field(default=None, alias="bwusageTopRegions")
    min_time: Optional[V1AlarmHistoryGet200ResponseHistoryInnerTime] = Field(default=None, alias="minTime")
    percent_changed: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="percentChanged")
    provider_count: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, alias="providerCount")
    region_count: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, alias="regionCount")
    site_count: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, alias="siteCount")
    usage_kbps: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="usageKbps")
    __properties: ClassVar[List[str]] = ["bwusageRoleSummary", "bwusageTopRegions", "minTime", "percentChanged", "providerCount", "regionCount", "siteCount", "usageKbps"]

    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 V1BwtrackerEnterpriseSummaryPost200ResponseBwusageSummary 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 bwusage_role_summary (list)
        _items = []
        if self.bwusage_role_summary:
            for _item_bwusage_role_summary in self.bwusage_role_summary:
                if _item_bwusage_role_summary:
                    _items.append(_item_bwusage_role_summary.to_dict())
            _dict['bwusageRoleSummary'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in bwusage_top_regions (list)
        _items = []
        if self.bwusage_top_regions:
            for _item_bwusage_top_regions in self.bwusage_top_regions:
                if _item_bwusage_top_regions:
                    _items.append(_item_bwusage_top_regions.to_dict())
            _dict['bwusageTopRegions'] = _items
        # override the default output from pydantic by calling `to_dict()` of min_time
        if self.min_time:
            _dict['minTime'] = self.min_time.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "bwusageRoleSummary": [V1BwtrackerEnterpriseSummaryPost200ResponseBwusageSummaryBwusageRoleSummaryInner.from_dict(_item) for _item in obj["bwusageRoleSummary"]] if obj.get("bwusageRoleSummary") is not None else None,
            "bwusageTopRegions": [V1BwtrackerEnterpriseSummaryPost200ResponseBwusageSummaryBwusageTopRegionsInner.from_dict(_item) for _item in obj["bwusageTopRegions"]] if obj.get("bwusageTopRegions") is not None else None,
            "minTime": V1AlarmHistoryGet200ResponseHistoryInnerTime.from_dict(obj["minTime"]) if obj.get("minTime") is not None else None,
            "percentChanged": obj.get("percentChanged"),
            "providerCount": obj.get("providerCount"),
            "regionCount": obj.get("regionCount"),
            "siteCount": obj.get("siteCount"),
            "usageKbps": obj.get("usageKbps")
        })
        return _obj


