# coding: utf-8

"""
    Moodle Webservice API

    Auto-generated OpenAPI spec for Moodle's Webservice API.

    The version of the OpenAPI document: 5.0.3 (Build: 20251006)
    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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.core_reportbuilder_reports_get_response_attributes_inner import CoreReportbuilderReportsGetResponseAttributesInner
from poodle_async_full.models.core_reportbuilder_reports_get_response_button import CoreReportbuilderReportsGetResponseButton
from poodle_async_full.models.core_reportbuilder_reports_get_response_cardview import CoreReportbuilderReportsGetResponseCardview
from poodle_async_full.models.core_reportbuilder_reports_get_response_conditions import CoreReportbuilderReportsGetResponseConditions
from poodle_async_full.models.core_reportbuilder_reports_get_response_filters import CoreReportbuilderReportsGetResponseFilters
from poodle_async_full.models.core_reportbuilder_reports_get_response_sidebarmenucards import CoreReportbuilderReportsGetResponseSidebarmenucards
from poodle_async_full.models.core_reportbuilder_reports_get_response_sorting import CoreReportbuilderReportsGetResponseSorting
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreReportbuilderReportsGetResponse(BaseModel):
    """
    CoreReportbuilderReportsGetResponse
    """ # noqa: E501
    area: StrictStr = Field(description="area")
    attributes: List[CoreReportbuilderReportsGetResponseAttributesInner] = Field(description="attributes")
    button: Optional[CoreReportbuilderReportsGetResponseButton] = None
    cardview: Optional[CoreReportbuilderReportsGetResponseCardview] = None
    classes: StrictStr = Field(description="classes")
    component: StrictStr = Field(description="component")
    conditiondata: Optional[StrictStr] = Field(description="conditiondata")
    conditions: Optional[CoreReportbuilderReportsGetResponseConditions] = None
    contextid: StrictInt = Field(description="contextid")
    editmode: StrictBool = Field(description="editmode")
    filters: Optional[CoreReportbuilderReportsGetResponseFilters] = None
    filtersapplied: StrictInt = Field(description="filtersapplied")
    filtersform: StrictStr = Field(description="filtersform")
    filterspresent: StrictBool = Field(description="filterspresent")
    id: StrictInt = Field(description="id")
    infocontainer: StrictStr = Field(description="infocontainer")
    itemid: StrictInt = Field(description="itemid")
    javascript: StrictStr = Field(description="javascript")
    name: Optional[StrictStr] = Field(description="name")
    settingsdata: Optional[StrictStr] = Field(description="settingsdata")
    sidebarmenucards: Optional[CoreReportbuilderReportsGetResponseSidebarmenucards] = None
    sorting: Optional[CoreReportbuilderReportsGetResponseSorting] = None
    source: StrictStr = Field(description="source")
    table: StrictStr = Field(description="table")
    timecreated: StrictInt = Field(description="timecreated")
    timemodified: StrictInt = Field(description="timemodified")
    type: StrictInt = Field(description="type")
    uniquerows: StrictBool = Field(description="uniquerows")
    usercreated: StrictInt = Field(description="usercreated")
    usermodified: StrictInt = Field(description="usermodified")
    __properties: ClassVar[List[str]] = ["area", "attributes", "button", "cardview", "classes", "component", "conditiondata", "conditions", "contextid", "editmode", "filters", "filtersapplied", "filtersform", "filterspresent", "id", "infocontainer", "itemid", "javascript", "name", "settingsdata", "sidebarmenucards", "sorting", "source", "table", "timecreated", "timemodified", "type", "uniquerows", "usercreated", "usermodified"]

    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 CoreReportbuilderReportsGetResponse 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 attributes (list)
        _items = []
        if self.attributes:
            for _item_attributes in self.attributes:
                if _item_attributes:
                    _items.append(_item_attributes.to_dict())
            _dict['attributes'] = _items
        # override the default output from pydantic by calling `to_dict()` of button
        if self.button:
            _dict['button'] = self.button.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cardview
        if self.cardview:
            _dict['cardview'] = self.cardview.to_dict()
        # override the default output from pydantic by calling `to_dict()` of conditions
        if self.conditions:
            _dict['conditions'] = self.conditions.to_dict()
        # override the default output from pydantic by calling `to_dict()` of filters
        if self.filters:
            _dict['filters'] = self.filters.to_dict()
        # override the default output from pydantic by calling `to_dict()` of sidebarmenucards
        if self.sidebarmenucards:
            _dict['sidebarmenucards'] = self.sidebarmenucards.to_dict()
        # override the default output from pydantic by calling `to_dict()` of sorting
        if self.sorting:
            _dict['sorting'] = self.sorting.to_dict()
        # set to None if conditiondata (nullable) is None
        # and model_fields_set contains the field
        if self.conditiondata is None and "conditiondata" in self.model_fields_set:
            _dict['conditiondata'] = None

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

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

        return _dict

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

        relaxed = settings.relaxe_all_models or "CoreReportbuilderReportsGetResponse" in settings.relaxed_models

        if not isinstance(obj, dict):
            return cls.model_construct(**obj) if relaxed else cls.model_validate(obj)

        data = {
            "area": obj.get("area") if obj.get("area") is not None else '',
            "attributes": [CoreReportbuilderReportsGetResponseAttributesInner.from_dict(_item) for _item in obj["attributes"]] if obj.get("attributes") is not None else None,
            "button": CoreReportbuilderReportsGetResponseButton.from_dict(obj["button"]) if obj.get("button") is not None else None,
            "cardview": CoreReportbuilderReportsGetResponseCardview.from_dict(obj["cardview"]) if obj.get("cardview") is not None else None,
            "classes": obj.get("classes") if obj.get("classes") is not None else '',
            "component": obj.get("component") if obj.get("component") is not None else '',
            "conditiondata": obj.get("conditiondata"),
            "conditions": CoreReportbuilderReportsGetResponseConditions.from_dict(obj["conditions"]) if obj.get("conditions") is not None else None,
            "contextid": obj.get("contextid") if obj.get("contextid") is not None else 0,
            "editmode": obj.get("editmode") if obj.get("editmode") is not None else False,
            "filters": CoreReportbuilderReportsGetResponseFilters.from_dict(obj["filters"]) if obj.get("filters") is not None else None,
            "filtersapplied": obj.get("filtersapplied") if obj.get("filtersapplied") is not None else 0,
            "filtersform": obj.get("filtersform") if obj.get("filtersform") is not None else '',
            "filterspresent": obj.get("filterspresent") if obj.get("filterspresent") is not None else False,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "infocontainer": obj.get("infocontainer") if obj.get("infocontainer") is not None else '',
            "itemid": obj.get("itemid") if obj.get("itemid") is not None else 0,
            "javascript": obj.get("javascript") if obj.get("javascript") is not None else '',
            "name": obj.get("name"),
            "settingsdata": obj.get("settingsdata"),
            "sidebarmenucards": CoreReportbuilderReportsGetResponseSidebarmenucards.from_dict(obj["sidebarmenucards"]) if obj.get("sidebarmenucards") is not None else None,
            "sorting": CoreReportbuilderReportsGetResponseSorting.from_dict(obj["sorting"]) if obj.get("sorting") is not None else None,
            "source": obj.get("source") if obj.get("source") is not None else '',
            "table": obj.get("table") if obj.get("table") is not None else '',
            "timecreated": obj.get("timecreated") if obj.get("timecreated") is not None else 0,
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0,
            "type": obj.get("type") if obj.get("type") is not None else 0,
            "uniquerows": obj.get("uniquerows") if obj.get("uniquerows") is not None else False,
            "usercreated": obj.get("usercreated") if obj.get("usercreated") is not None else 0,
            "usermodified": obj.get("usermodified") if obj.get("usermodified") is not None else 0
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


