# 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, StrictFloat, StrictInt
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModH5pactivityGetAttemptsResponseUsersattemptsInnerAttemptsInner(BaseModel):
    """
    ModH5pactivityGetAttemptsResponseUsersattemptsInnerAttemptsInner
    """ # noqa: E501
    attempt: Optional[StrictInt] = Field(description="Attempt number")
    completion: Optional[StrictInt] = Field(default=None, description="Attempt completion")
    duration: Optional[StrictInt] = Field(description="Attempt duration in seconds")
    h5pactivityid: Optional[StrictInt] = Field(description="ID of the H5P activity")
    id: Optional[StrictInt] = Field(description="ID of the context")
    maxscore: Optional[StrictInt] = Field(description="Attempt max score")
    rawscore: Optional[StrictInt] = Field(description="Attempt score value")
    scaled: Optional[Union[StrictFloat, StrictInt]] = Field(description="Attempt scaled")
    success: Optional[StrictInt] = Field(default=None, description="Attempt success")
    timecreated: Optional[StrictInt] = Field(description="Attempt creation")
    timemodified: Optional[StrictInt] = Field(description="Attempt modified")
    userid: Optional[StrictInt] = Field(description="ID of the user")
    __properties: ClassVar[List[str]] = ["attempt", "completion", "duration", "h5pactivityid", "id", "maxscore", "rawscore", "scaled", "success", "timecreated", "timemodified", "userid"]

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

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

        return _dict

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

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

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

        data = {
            "attempt": obj.get("attempt"),
            "completion": obj.get("completion"),
            "duration": obj.get("duration"),
            "h5pactivityid": obj.get("h5pactivityid"),
            "id": obj.get("id"),
            "maxscore": obj.get("maxscore"),
            "rawscore": obj.get("rawscore"),
            "scaled": obj.get("scaled"),
            "success": obj.get("success"),
            "timecreated": obj.get("timecreated"),
            "timemodified": obj.get("timemodified"),
            "userid": obj.get("userid")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


