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

from poodle_async_full.configuration import settings

class CoreCompletionGetActivitiesCompletionStatusResponseStatusesInner(BaseModel):
    """
    Activity
    """ # noqa: E501
    cmid: Optional[StrictInt] = Field(description="course module ID")
    details: Optional[List[CoreCompletionGetActivitiesCompletionStatusResponseStatusesInnerDetailsInner]] = Field(default=None, description="Completion status details")
    hascompletion: Optional[StrictBool] = Field(default=None, description="Whether this activity module has completion enabled")
    instance: Optional[StrictInt] = Field(description="instance ID")
    isautomatic: Optional[StrictBool] = Field(default=None, description="Whether this activity module instance tracks completion automatically.")
    isoverallcomplete: Optional[StrictBool] = Field(default=None, description="Whether the overall completion state of this course module should be marked as complete or not.")
    istrackeduser: Optional[StrictBool] = Field(default=None, description="Whether completion is being tracked for this user.")
    modname: Optional[StrictStr] = Field(description="activity module name")
    overrideby: Optional[StrictInt] = Field(default=None, description="The user id who has overriden the status, or null")
    state: Optional[StrictInt] = Field(description="Completion state value:                                     0 means incomplete,                                     1 complete,                                     2 complete pass,                                     3 complete fail")
    timecompleted: Optional[StrictInt] = Field(description="timestamp for completed activity")
    tracking: Optional[StrictInt] = Field(description="type of tracking:                                     0 means none,                                     1 manual,                                     2 automatic")
    uservisible: Optional[StrictBool] = Field(default=None, description="Whether this activity is visible to the user.")
    valueused: Optional[StrictBool] = Field(default=None, description="Whether the completion status affects the availability of another activity.")
    __properties: ClassVar[List[str]] = ["cmid", "details", "hascompletion", "instance", "isautomatic", "isoverallcomplete", "istrackeduser", "modname", "overrideby", "state", "timecompleted", "tracking", "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 CoreCompletionGetActivitiesCompletionStatusResponseStatusesInner 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 cmid (nullable) is None
        # and model_fields_set contains the field
        if self.cmid is None and "cmid" in self.model_fields_set:
            _dict['cmid'] = None

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

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

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

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

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

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

        # 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

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

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

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

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

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

        return _dict

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

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

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

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


