# coding: utf-8

"""
    AdInsightService

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union, Set
from openapi_client.models.adinsight.day_month_and_year import DayMonthAndYear
from openapi_client.models.adinsight.entity_type import EntityType
from openapi_client.models.adinsight.kpi_type import KPIType
from openapi_client.models.adinsight.performance_insights_message import PerformanceInsightsMessage
from typing_extensions import Self

class PerformanceInsightsDetail(BaseModel):
    """
    PerformanceInsightsDetail
    """ # noqa: E501
    entity_id: Optional[StrictStr] = Field(default=None, alias="EntityId")
    entity_type: Optional[EntityType] = Field(default=None, alias="EntityType")
    kpi_type: Optional[KPIType] = Field(default=None, alias="KPIType")
    var_date: Optional[DayMonthAndYear] = Field(default=None, alias="Date")
    description: Optional[PerformanceInsightsMessage] = Field(default=None, alias="Description")
    root_causes: Optional[List[Optional[PerformanceInsightsMessage]]] = Field(default=None, alias="RootCauses")
    actions: Optional[List[Optional[PerformanceInsightsMessage]]] = Field(default=None, alias="Actions")
    __properties: ClassVar[List[str]] = ["EntityId", "EntityType", "KPIType", "Date", "Description", "RootCauses", "Actions"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )
	

    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 var_date
        if self.var_date:
            _dict['Date'] = self.var_date.to_dict()
        # override the default output from pydantic by calling `to_dict()` of description
        if self.description:
            _dict['Description'] = self.description.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in root_causes (list)
        _items = []
        if self.root_causes:
            for _item_root_causes in self.root_causes:
                if _item_root_causes:
                    _items.append(_item_root_causes.to_dict())
            _dict['RootCauses'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in actions (list)
        _items = []
        if self.actions:
            for _item_actions in self.actions:
                if _item_actions:
                    _items.append(_item_actions.to_dict())
            _dict['Actions'] = _items
        # set to None if entity_id (nullable) is None
        # and model_fields_set contains the field
        if self.entity_id is None and "entity_id" in self.model_fields_set:
            _dict['EntityId'] = None

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "EntityId": obj.get("EntityId") if obj.get("EntityId") is not None else None,
                        "EntityType": obj.get("EntityType") if obj.get("EntityType") is not None else None,
                        "KPIType": obj.get("KPIType") if obj.get("KPIType") is not None else None,
                        "Date": DayMonthAndYear.from_dict(obj["Date"]) if obj.get("Date") is not None else None,
                        "Description": PerformanceInsightsMessage.from_dict(obj["Description"]) if obj.get("Description") is not None else None,
                        "RootCauses": [PerformanceInsightsMessage.from_dict(_item) for _item in obj["RootCauses"]] if obj.get("RootCauses") is not None else None,
                        "Actions": [PerformanceInsightsMessage.from_dict(_item) for _item in obj["Actions"]] if obj.get("Actions") is not None else None
        })
        return _obj
