# 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_competency_read_user_evidence_response_files_inner import CoreCompetencyReadUserEvidenceResponseFilesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModFeedbackGetAnalysisResponseItemsdataInnerItem(BaseModel):
    """
    ModFeedbackGetAnalysisResponseItemsdataInnerItem
    """ # noqa: E501
    dependitem: StrictInt = Field(description="The item id this item depend on.")
    dependvalue: StrictStr = Field(description="The depend value.")
    feedback: StrictInt = Field(description="The feedback instance id this records belongs to.")
    hasvalue: StrictInt = Field(description="Whether it has a value or not.")
    id: StrictInt = Field(description="The record id.")
    itemfiles: List[CoreCompetencyReadUserEvidenceResponseFilesInner] = Field(description="itemfiles")
    itemnumber: Optional[StrictInt] = Field(description="The item position number")
    label: StrictStr = Field(description="The item label.")
    name: StrictStr = Field(description="The item name.")
    nameformat: Optional[StrictInt] = Field(default=1, description="name format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    options: StrictStr = Field(description="Different additional settings for the item (question).")
    otherdata: Optional[StrictStr] = Field(description="Additional data that may be required by external functions")
    position: StrictInt = Field(description="The position in the list of questions.")
    presentation: StrictStr = Field(description="The text describing the item or the available possible answers.")
    presentationformat: Optional[StrictInt] = Field(default=1, description="presentation format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    required: StrictBool = Field(description="Whether is a item (question) required or not.")
    template: StrictInt = Field(description="If it belogns to a template, the template id.")
    typ: StrictStr = Field(description="The type of the item.")
    __properties: ClassVar[List[str]] = ["dependitem", "dependvalue", "feedback", "hasvalue", "id", "itemfiles", "itemnumber", "label", "name", "nameformat", "options", "otherdata", "position", "presentation", "presentationformat", "required", "template", "typ"]

    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 ModFeedbackGetAnalysisResponseItemsdataInnerItem 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 itemfiles (list)
        _items = []
        if self.itemfiles:
            for _item_itemfiles in self.itemfiles:
                if _item_itemfiles:
                    _items.append(_item_itemfiles.to_dict())
            _dict['itemfiles'] = _items
        # set to None if itemnumber (nullable) is None
        # and model_fields_set contains the field
        if self.itemnumber is None and "itemnumber" in self.model_fields_set:
            _dict['itemnumber'] = None

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

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

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

        return _dict

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

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

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

        data = {
            "dependitem": obj.get("dependitem") if obj.get("dependitem") is not None else 0,
            "dependvalue": obj.get("dependvalue") if obj.get("dependvalue") is not None else '',
            "feedback": obj.get("feedback") if obj.get("feedback") is not None else 0,
            "hasvalue": obj.get("hasvalue") if obj.get("hasvalue") is not None else 0,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "itemfiles": [CoreCompetencyReadUserEvidenceResponseFilesInner.from_dict(_item) for _item in obj["itemfiles"]] if obj.get("itemfiles") is not None else None,
            "itemnumber": obj.get("itemnumber"),
            "label": obj.get("label") if obj.get("label") is not None else '',
            "name": obj.get("name") if obj.get("name") is not None else '',
            "nameformat": obj.get("nameformat") if obj.get("nameformat") is not None else 1,
            "options": obj.get("options") if obj.get("options") is not None else '',
            "otherdata": obj.get("otherdata"),
            "position": obj.get("position") if obj.get("position") is not None else 0,
            "presentation": obj.get("presentation") if obj.get("presentation") is not None else '',
            "presentationformat": obj.get("presentationformat") if obj.get("presentationformat") is not None else 1,
            "required": obj.get("required") if obj.get("required") is not None else False,
            "template": obj.get("template") if obj.get("template") is not None else 0,
            "typ": obj.get("typ") if obj.get("typ") is not None else ''
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


