# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.core_blog_get_entries_response_entries_inner_attachmentfiles_inner import CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner
from poodle_async_full.models.mod_h5pactivity_get_h5pactivities_by_courses_response_h5pactivities_inner_deployedfile import ModH5pactivityGetH5pactivitiesByCoursesResponseH5pactivitiesInnerDeployedfile
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModH5pactivityGetH5pactivitiesByCoursesResponseH5pactivitiesInner(BaseModel):
    """
    ModH5pactivityGetH5pactivitiesByCoursesResponseH5pactivitiesInner
    """ # noqa: E501
    contenthash: Optional[StrictStr] = Field(default='', description="Sha1 hash of file content.")
    context: StrictInt = Field(description="context")
    course: StrictInt = Field(description="Course id this h5p activity is part of.")
    coursemodule: StrictInt = Field(description="coursemodule")
    deployedfile: Optional[ModH5pactivityGetH5pactivitiesByCoursesResponseH5pactivitiesInnerDeployedfile] = None
    displayoptions: StrictInt = Field(description="H5P Button display options.")
    enabletracking: StrictInt = Field(description="Enable xAPI tracking.")
    grade: Optional[StrictInt] = Field(default=0, description="The maximum grade for submission.")
    grademethod: StrictInt = Field(description="Which H5P attempt is used for grading.")
    id: StrictInt = Field(description="The primary key of the record.")
    intro: Optional[StrictStr] = Field(description="H5P activity description.")
    introfiles: List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner] = Field(description="introfiles")
    introformat: Optional[StrictInt] = Field(default=0, description="intro format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    name: StrictStr = Field(description="The name of the activity module instance.")
    package: List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner] = Field(description="package")
    timecreated: Optional[StrictInt] = Field(default=0, description="Timestamp of when the instance was added to the course.")
    timemodified: Optional[StrictInt] = Field(default=0, description="Timestamp of when the instance was last modified.")
    __properties: ClassVar[List[str]] = ["contenthash", "context", "course", "coursemodule", "deployedfile", "displayoptions", "enabletracking", "grade", "grademethod", "id", "intro", "introfiles", "introformat", "name", "package", "timecreated", "timemodified"]

    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 ModH5pactivityGetH5pactivitiesByCoursesResponseH5pactivitiesInner 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 deployedfile
        if self.deployedfile:
            _dict['deployedfile'] = self.deployedfile.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in introfiles (list)
        _items = []
        if self.introfiles:
            for _item_introfiles in self.introfiles:
                if _item_introfiles:
                    _items.append(_item_introfiles.to_dict())
            _dict['introfiles'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in package (list)
        _items = []
        if self.package:
            for _item_package in self.package:
                if _item_package:
                    _items.append(_item_package.to_dict())
            _dict['package'] = _items
        # set to None if intro (nullable) is None
        # and model_fields_set contains the field
        if self.intro is None and "intro" in self.model_fields_set:
            _dict['intro'] = None

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

        return _dict

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

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

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

        data = {
            "contenthash": obj.get("contenthash") if obj.get("contenthash") is not None else '',
            "context": obj.get("context") if obj.get("context") is not None else 0,
            "course": obj.get("course") if obj.get("course") is not None else 0,
            "coursemodule": obj.get("coursemodule") if obj.get("coursemodule") is not None else 0,
            "deployedfile": ModH5pactivityGetH5pactivitiesByCoursesResponseH5pactivitiesInnerDeployedfile.from_dict(obj["deployedfile"]) if obj.get("deployedfile") is not None else None,
            "displayoptions": obj.get("displayoptions") if obj.get("displayoptions") is not None else 0,
            "enabletracking": obj.get("enabletracking") if obj.get("enabletracking") is not None else 0,
            "grade": obj.get("grade") if obj.get("grade") is not None else 0,
            "grademethod": obj.get("grademethod") if obj.get("grademethod") is not None else 0,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "intro": obj.get("intro") if obj.get("intro") is not None else '',
            "introfiles": [CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner.from_dict(_item) for _item in obj["introfiles"]] if obj.get("introfiles") is not None else None,
            "introformat": obj.get("introformat") if obj.get("introformat") is not None else 0,
            "name": obj.get("name") if obj.get("name") is not None else '',
            "package": [CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner.from_dict(_item) for _item in obj["package"]] if obj.get("package") is not None else None,
            "timecreated": obj.get("timecreated") if obj.get("timecreated") is not None else 0,
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


