# coding: utf-8

"""
    Moodle Webservice API

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

    The version of the OpenAPI document: 5.0.2 (Build: 20250811)
    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
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_mini.models.core_course_get_contents_response_inner_modules_inner_completiondata_details_inner import CoreCourseGetContentsResponseInnerModulesInnerCompletiondataDetailsInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_mini.configuration import settings

class CoreCourseGetContentsResponseInnerModulesInnerCompletiondata(BaseModel):
    """
    CoreCourseGetContentsResponseInnerModulesInnerCompletiondata
    """ # noqa: E501
    details: List[CoreCourseGetContentsResponseInnerModulesInnerCompletiondataDetailsInner] = Field(description="An array of completion details containing the description and status.")
    hascompletion: StrictBool = Field(description="Whether this activity module has completion enabled.")
    isautomatic: StrictBool = Field(description="Whether this activity module instance tracks completion automatically.")
    isoverallcomplete: Optional[StrictBool] = Field(default=False, description="Whether the overall completion state of this course module should be marked as complete or not.")
    istrackeduser: StrictBool = Field(description="Checks whether completion is being tracked for this user.")
    overrideby: Optional[StrictInt] = Field(description="user ID that has overridden the completion state of this activity for the user.")
    state: StrictInt = Field(description="overall completion state of this course module.")
    timecompleted: StrictInt = Field(description="course completion timestamp.")
    uservisible: StrictBool = Field(description="Whether this activity is visible to user.")
    valueused: StrictBool = Field(description="True if module is used in a condition, false otherwise.")
    __properties: ClassVar[List[str]] = ["details", "hascompletion", "isautomatic", "isoverallcomplete", "istrackeduser", "overrideby", "state", "timecompleted", "uservisible", "valueused"]

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

        return _dict

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

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

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

        data = {
            "details": [CoreCourseGetContentsResponseInnerModulesInnerCompletiondataDetailsInner.from_dict(_item) for _item in obj["details"]] if obj.get("details") is not None else None,
            "hascompletion": obj.get("hascompletion") if obj.get("hascompletion") is not None else False,
            "isautomatic": obj.get("isautomatic") if obj.get("isautomatic") is not None else False,
            "isoverallcomplete": obj.get("isoverallcomplete") if obj.get("isoverallcomplete") is not None else False,
            "istrackeduser": obj.get("istrackeduser") if obj.get("istrackeduser") is not None else False,
            "overrideby": obj.get("overrideby"),
            "state": obj.get("state") if obj.get("state") is not None else 0,
            "timecompleted": obj.get("timecompleted") if obj.get("timecompleted") is not None else 0,
            "uservisible": obj.get("uservisible") if obj.get("uservisible") is not None else False,
            "valueused": obj.get("valueused") if obj.get("valueused") is not None else False
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


