# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from thousandeyes_sdk.dashboards.models.api_widget import ApiWidget
from thousandeyes_sdk.dashboards.models.dashboard_layout import DashboardLayout
from thousandeyes_sdk.dashboards.models.dashboard_links import DashboardLinks
from thousandeyes_sdk.dashboards.models.default_timespan import DefaultTimespan
from typing import Optional, Set
from typing_extensions import Self

class ApiDashboard(BaseModel):
    """
    Dashboard upon which this dashboard snapshot is based upon.
    """ # noqa: E501
    global_filter_id: Optional[StrictStr] = Field(default=None, description="Default global dashboard filter ID (obtained from `/dashboards/filters` endpoint).", alias="globalFilterId")
    account_id: Optional[StrictInt] = Field(default=None, description="Identifier for the account group associated with a dashboard.", alias="accountId")
    created_by: Optional[StrictInt] = Field(default=None, description="Identifier for the user that created a dashboard.", alias="createdBy")
    modified_by: Optional[StrictInt] = Field(default=None, description="Identifier for the user that last modified a dashboard.", alias="modifiedBy")
    modified_date: Optional[StrictStr] = Field(default=None, description="UTC date/time when a dashboard was last modified.", alias="modifiedDate")
    global_override: Optional[StrictBool] = Field(default=None, description="When set to `true`, the defaultTimespan is used and overrides the widget's timespan. If set to `false`, the the widget's timespan is used.", alias="globalOverride")
    migrated_report: Optional[StrictBool] = Field(default=None, description="True if this dashboard was previously a report.", alias="migratedReport")
    api_link: Optional[List[Dict[str, Any]]] = Field(default=None, description="A links array containing the self and the snapshots links.", alias="apiLink")
    dashboard_id: Optional[StrictStr] = Field(default=None, description="Identifier of a dashboard.", alias="dashboardId")
    title: Optional[StrictStr] = Field(default=None, description="Title of a dashboard.")
    is_built_in: Optional[StrictBool] = Field(default=None, description="Indicates if a dashboard is built-in. True for built-in dashboards, false for user-created dashboards.", alias="isBuiltIn")
    aid: Optional[StrictStr] = Field(default=None, description="Identifier for the account group associated with a dashboard.")
    dashboard_created_by: Optional[StrictStr] = Field(default=None, description="Identifier for the user that created a dashboard.", alias="dashboardCreatedBy")
    dashboard_modified_by: Optional[StrictStr] = Field(default=None, description="Identifier for the user that last modified a dashboard.", alias="dashboardModifiedBy")
    dashboard_modified_date: Optional[datetime] = Field(default=None, description="UTC date/time when a dashboard was last modified (ISO date-time format).", alias="dashboardModifiedDate")
    is_private: Optional[StrictBool] = Field(default=None, description="A dashboard can be viewed by other users in the account. If true, only the creator of the dashboard may view it. If false, all users in the same account may view it.", alias="isPrivate")
    is_default_for_user: Optional[StrictBool] = Field(default=None, description="Indicates whether this dashboard is the user's default. True for default, false if not.", alias="isDefaultForUser")
    is_default_for_account: Optional[StrictBool] = Field(default=None, description="Indicates whether this dashboard is the account group's default. True for default, false if not.", alias="isDefaultForAccount")
    widgets: Optional[List[ApiWidget]] = None
    description: Optional[StrictStr] = Field(default=None, description="A text description of the dashboard's purpose and functionality. This information assists users in understanding the dashboard but isn't displayed when viewing a dashboard.")
    default_timespan: Optional[DefaultTimespan] = Field(default=None, alias="defaultTimespan")
    is_global_override: Optional[StrictBool] = Field(default=None, description="When set to `true`, the defaultTimespan is used and overrides the widget's timespan. If set to `false`, the the widget's timespan is used.", alias="isGlobalOverride")
    is_migrated_report: Optional[StrictBool] = Field(default=None, description="True if this dashboard was previously a report.", alias="isMigratedReport")
    layout: Optional[DashboardLayout] = None
    links: Optional[DashboardLinks] = Field(default=None, alias="_links")
    __properties: ClassVar[List[str]] = ["globalFilterId", "accountId", "createdBy", "modifiedBy", "modifiedDate", "globalOverride", "migratedReport", "apiLink", "dashboardId", "title", "isBuiltIn", "aid", "dashboardCreatedBy", "dashboardModifiedBy", "dashboardModifiedDate", "isPrivate", "isDefaultForUser", "isDefaultForAccount", "widgets", "description", "defaultTimespan", "isGlobalOverride", "isMigratedReport", "layout", "_links"]

    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 ApiDashboard 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "account_id",
            "created_by",
            "modified_by",
            "modified_date",
            "migrated_report",
            "dashboard_id",
            "is_built_in",
            "aid",
            "dashboard_created_by",
            "dashboard_modified_by",
            "dashboard_modified_date",
            "is_default_for_user",
            "is_default_for_account",
            "is_migrated_report",
        ])

        _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 widgets (list)
        _items = []
        if self.widgets:
            for _item in self.widgets:
                if _item:
                    _items.append(_item.to_dict())
            _dict['widgets'] = _items
        # override the default output from pydantic by calling `to_dict()` of default_timespan
        if self.default_timespan:
            _dict['defaultTimespan'] = self.default_timespan.to_dict()
        # override the default output from pydantic by calling `to_dict()` of layout
        if self.layout:
            _dict['layout'] = self.layout.to_dict()
        # override the default output from pydantic by calling `to_dict()` of links
        if self.links:
            _dict['_links'] = self.links.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "globalFilterId": obj.get("globalFilterId"),
            "accountId": obj.get("accountId"),
            "createdBy": obj.get("createdBy"),
            "modifiedBy": obj.get("modifiedBy"),
            "modifiedDate": obj.get("modifiedDate"),
            "globalOverride": obj.get("globalOverride"),
            "migratedReport": obj.get("migratedReport"),
            "apiLink": obj.get("apiLink"),
            "dashboardId": obj.get("dashboardId"),
            "title": obj.get("title"),
            "isBuiltIn": obj.get("isBuiltIn"),
            "aid": obj.get("aid"),
            "dashboardCreatedBy": obj.get("dashboardCreatedBy"),
            "dashboardModifiedBy": obj.get("dashboardModifiedBy"),
            "dashboardModifiedDate": obj.get("dashboardModifiedDate"),
            "isPrivate": obj.get("isPrivate"),
            "isDefaultForUser": obj.get("isDefaultForUser"),
            "isDefaultForAccount": obj.get("isDefaultForAccount"),
            "widgets": [ApiWidget.from_dict(_item) for _item in obj["widgets"]] if obj.get("widgets") is not None else None,
            "description": obj.get("description"),
            "defaultTimespan": DefaultTimespan.from_dict(obj["defaultTimespan"]) if obj.get("defaultTimespan") is not None else None,
            "isGlobalOverride": obj.get("isGlobalOverride"),
            "isMigratedReport": obj.get("isMigratedReport"),
            "layout": DashboardLayout.from_dict(obj["layout"]) if obj.get("layout") is not None else None,
            "_links": DashboardLinks.from_dict(obj["_links"]) if obj.get("_links") is not None else None
        })
        return _obj


