# 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_blog_get_entries_response_entries_inner_tags_inner import CoreBlogGetEntriesResponseEntriesInnerTagsInner
from poodle_async_full.models.core_competency_create_plan_response_reviewer import CoreCompetencyCreatePlanResponseReviewer
from poodle_async_full.models.core_reportbuilder_list_reports_response_reports_inner_customfields import CoreReportbuilderListReportsResponseReportsInnerCustomfields
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreReportbuilderListReportsResponseReportsInner(BaseModel):
    """
    CoreReportbuilderListReportsResponseReportsInner
    """ # noqa: E501
    area: StrictStr = Field(description="area")
    component: StrictStr = Field(description="component")
    conditiondata: Optional[StrictStr] = Field(description="conditiondata")
    contextid: StrictInt = Field(description="contextid")
    customfields: CoreReportbuilderListReportsResponseReportsInnerCustomfields
    id: StrictInt = Field(description="id")
    itemid: StrictInt = Field(description="itemid")
    modifiedby: CoreCompetencyCreatePlanResponseReviewer
    name: Optional[StrictStr] = Field(description="name")
    settingsdata: Optional[StrictStr] = Field(description="settingsdata")
    source: StrictStr = Field(description="source")
    sourcename: Optional[StrictStr] = Field(description="sourcename")
    tags: List[CoreBlogGetEntriesResponseEntriesInnerTagsInner] = Field(description="tags")
    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", "component", "conditiondata", "contextid", "customfields", "id", "itemid", "modifiedby", "name", "settingsdata", "source", "sourcename", "tags", "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 CoreReportbuilderListReportsResponseReportsInner 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 customfields
        if self.customfields:
            _dict['customfields'] = self.customfields.to_dict()
        # override the default output from pydantic by calling `to_dict()` of modifiedby
        if self.modifiedby:
            _dict['modifiedby'] = self.modifiedby.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in tags (list)
        _items = []
        if self.tags:
            for _item_tags in self.tags:
                if _item_tags:
                    _items.append(_item_tags.to_dict())
            _dict['tags'] = _items
        # 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

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

        return _dict

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

        relaxed = settings.relaxe_all_models or "CoreReportbuilderListReportsResponseReportsInner" 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 '',
            "component": obj.get("component") if obj.get("component") is not None else '',
            "conditiondata": obj.get("conditiondata"),
            "contextid": obj.get("contextid") if obj.get("contextid") is not None else 0,
            "customfields": CoreReportbuilderListReportsResponseReportsInnerCustomfields.from_dict(obj["customfields"]) if obj.get("customfields") is not None else None,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "itemid": obj.get("itemid") if obj.get("itemid") is not None else 0,
            "modifiedby": CoreCompetencyCreatePlanResponseReviewer.from_dict(obj["modifiedby"]) if obj.get("modifiedby") is not None else None,
            "name": obj.get("name"),
            "settingsdata": obj.get("settingsdata"),
            "source": obj.get("source") if obj.get("source") is not None else '',
            "sourcename": obj.get("sourcename"),
            "tags": [CoreBlogGetEntriesResponseEntriesInnerTagsInner.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None,
            "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


