# 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.mod_h5pactivity_get_results_response_attempts_inner_results_inner_options_inner import ModH5pactivityGetResultsResponseAttemptsInnerResultsInnerOptionsInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModH5pactivityGetResultsResponseAttemptsInnerResultsInner(BaseModel):
    """
    A single result statement tracking information
    """ # noqa: E501
    answerlabel: Optional[StrictStr] = Field(default=None, description="Label used for user answers")
    attemptid: Optional[StrictInt] = Field(description="ID of the H5P attempt")
    completion: Optional[StrictInt] = Field(default=None, description="Result completion")
    content: Optional[StrictStr] = Field(default=None, description="Result extra content")
    correctlabel: Optional[StrictStr] = Field(default=None, description="Label used for correct answers")
    description: Optional[StrictStr] = Field(description="Result description")
    duration: Optional[StrictInt] = Field(default=0, description="Result duration in seconds")
    id: Optional[StrictInt] = Field(description="ID of the context")
    interactiontype: Optional[StrictStr] = Field(description="Interaction type")
    maxscore: Optional[StrictInt] = Field(description="Result max score")
    options: Optional[List[ModH5pactivityGetResultsResponseAttemptsInnerResultsInnerOptionsInner]] = Field(default=None, description="The statement options")
    optionslabel: Optional[StrictStr] = Field(default=None, description="Label used for result options")
    rawscore: Optional[StrictInt] = Field(description="Result score value")
    subcontent: Optional[StrictStr] = Field(description="Subcontent identifier")
    success: Optional[StrictInt] = Field(default=None, description="Result success")
    timecreated: Optional[StrictInt] = Field(description="Result creation")
    track: Optional[StrictBool] = Field(default=None, description="If the result has valid track information")
    __properties: ClassVar[List[str]] = ["answerlabel", "attemptid", "completion", "content", "correctlabel", "description", "duration", "id", "interactiontype", "maxscore", "options", "optionslabel", "rawscore", "subcontent", "success", "timecreated", "track"]

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

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

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

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

        # set to None if correctlabel (nullable) is None
        # and model_fields_set contains the field
        if self.correctlabel is None and "correctlabel" in self.model_fields_set:
            _dict['correctlabel'] = 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 duration (nullable) is None
        # and model_fields_set contains the field
        if self.duration is None and "duration" in self.model_fields_set:
            _dict['duration'] = None

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "answerlabel": obj.get("answerlabel"),
            "attemptid": obj.get("attemptid"),
            "completion": obj.get("completion"),
            "content": obj.get("content"),
            "correctlabel": obj.get("correctlabel"),
            "description": obj.get("description"),
            "duration": obj.get("duration") if obj.get("duration") is not None else 0,
            "id": obj.get("id"),
            "interactiontype": obj.get("interactiontype"),
            "maxscore": obj.get("maxscore"),
            "options": [ModH5pactivityGetResultsResponseAttemptsInnerResultsInnerOptionsInner.from_dict(_item) for _item in obj["options"]] if obj.get("options") is not None else None,
            "optionslabel": obj.get("optionslabel"),
            "rawscore": obj.get("rawscore"),
            "subcontent": obj.get("subcontent"),
            "success": obj.get("success"),
            "timecreated": obj.get("timecreated"),
            "track": obj.get("track")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


