# coding: utf-8

"""
    Dashboards API

    Manage ThousandEyes Dashboards.

    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 thousandeyes_sdk.dashboards.models.api_agent_status_agent import ApiAgentStatusAgent
from thousandeyes_sdk.dashboards.models.api_agent_status_summary import ApiAgentStatusSummary
from thousandeyes_sdk.dashboards.models.api_alert_list_alert import ApiAlertListAlert
from thousandeyes_sdk.dashboards.models.api_dashboard_asw import ApiDashboardAsw
from thousandeyes_sdk.dashboards.models.api_multi_metric_column_data import ApiMultiMetricColumnData
from thousandeyes_sdk.dashboards.models.api_numbers_card_data import ApiNumbersCardData
from thousandeyes_sdk.dashboards.models.api_test_table_data import ApiTestTableData
from thousandeyes_sdk.dashboards.models.api_widget_data_point import ApiWidgetDataPoint
from typing import Optional, Set
from typing_extensions import Self

class ApiWidgetsDataV2(BaseModel):
    """
    Data of a widget.
    """ # noqa: E501
    cards: Optional[List[ApiNumbersCardData]] = None
    columns: Optional[List[ApiMultiMetricColumnData]] = None
    points: Optional[List[ApiWidgetDataPoint]] = None
    tests: Optional[List[ApiTestTableData]] = None
    start_round: Optional[StrictInt] = Field(default=None, description="Epoch time (seconds) indicating the start time of the round.", alias="startRound")
    alert_suppression_windows: Optional[List[ApiDashboardAsw]] = Field(default=None, alias="alertSuppressionWindows")
    total_alerts: Optional[StrictInt] = Field(default=None, description="Total number of active alerts within configured timespan.", alias="totalAlerts")
    active_alerts: Optional[StrictInt] = Field(default=None, description="Total number of currently active alerts.", alias="activeAlerts")
    alerts: Optional[List[ApiAlertListAlert]] = None
    summary: Optional[ApiAgentStatusSummary] = None
    agents: Optional[List[ApiAgentStatusAgent]] = None
    status: Optional[StrictStr] = Field(default=None, description="Message for not fully configured card or no data.")
    __properties: ClassVar[List[str]] = ["cards", "columns", "points", "tests", "startRound", "alertSuppressionWindows", "totalAlerts", "activeAlerts", "alerts", "summary", "agents", "status"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
        extra="allow",
    )


    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 self.model_dump_json(by_alias=True, exclude_unset=True, exclude_none=True)

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ApiWidgetsDataV2 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 cards (list)
        _items = []
        if self.cards:
            for _item in self.cards:
                if _item:
                    _items.append(_item.to_dict())
            _dict['cards'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in columns (list)
        _items = []
        if self.columns:
            for _item in self.columns:
                if _item:
                    _items.append(_item.to_dict())
            _dict['columns'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in points (list)
        _items = []
        if self.points:
            for _item in self.points:
                if _item:
                    _items.append(_item.to_dict())
            _dict['points'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in tests (list)
        _items = []
        if self.tests:
            for _item in self.tests:
                if _item:
                    _items.append(_item.to_dict())
            _dict['tests'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in alert_suppression_windows (list)
        _items = []
        if self.alert_suppression_windows:
            for _item in self.alert_suppression_windows:
                if _item:
                    _items.append(_item.to_dict())
            _dict['alertSuppressionWindows'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in alerts (list)
        _items = []
        if self.alerts:
            for _item in self.alerts:
                if _item:
                    _items.append(_item.to_dict())
            _dict['alerts'] = _items
        # override the default output from pydantic by calling `to_dict()` of summary
        if self.summary:
            _dict['summary'] = self.summary.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in agents (list)
        _items = []
        if self.agents:
            for _item in self.agents:
                if _item:
                    _items.append(_item.to_dict())
            _dict['agents'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "cards": [ApiNumbersCardData.from_dict(_item) for _item in obj["cards"]] if obj.get("cards") is not None else None,
            "columns": [ApiMultiMetricColumnData.from_dict(_item) for _item in obj["columns"]] if obj.get("columns") is not None else None,
            "points": [ApiWidgetDataPoint.from_dict(_item) for _item in obj["points"]] if obj.get("points") is not None else None,
            "tests": [ApiTestTableData.from_dict(_item) for _item in obj["tests"]] if obj.get("tests") is not None else None,
            "startRound": obj.get("startRound"),
            "alertSuppressionWindows": [ApiDashboardAsw.from_dict(_item) for _item in obj["alertSuppressionWindows"]] if obj.get("alertSuppressionWindows") is not None else None,
            "totalAlerts": obj.get("totalAlerts"),
            "activeAlerts": obj.get("activeAlerts"),
            "alerts": [ApiAlertListAlert.from_dict(_item) for _item in obj["alerts"]] if obj.get("alerts") is not None else None,
            "summary": ApiAgentStatusSummary.from_dict(obj["summary"]) if obj.get("summary") is not None else None,
            "agents": [ApiAgentStatusAgent.from_dict(_item) for _item in obj["agents"]] if obj.get("agents") is not None else None,
            "status": obj.get("status")
        })
        return _obj


