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

from poodle_async_full.configuration import settings

class ModLessonGetLessonResponseLesson(BaseModel):
    """
    ModLessonGetLessonResponseLesson
    """ # noqa: E501
    activitylink: Optional[StrictInt] = Field(default=0, description="Id of the next activity to be linked once the lesson is completed")
    allowofflineattempts: StrictBool = Field(description="Whether to allow the lesson to be attempted offline in the mobile app")
    available: Optional[StrictInt] = Field(default=0, description="Available from")
    bgcolor: Optional[StrictStr] = Field(default='', description="Slideshow bgcolor")
    completionendreached: Optional[StrictInt] = Field(default=0, description="Require end reached for completion?")
    completiontimespent: Optional[StrictInt] = Field(default=0, description="Student must do this activity at least for")
    conditions: Optional[StrictStr] = Field(default='', description="Conditions to enable the lesson")
    course: StrictInt = Field(description="Foreign key reference to the course this lesson is part of.")
    coursemodule: StrictInt = Field(description="Course module id.")
    custom: Optional[StrictBool] = Field(default=False, description="Custom scoring?")
    deadline: Optional[StrictInt] = Field(default=0, description="Available until")
    dependency: Optional[StrictInt] = Field(default=0, description="Dependent on (another lesson id)")
    displayleft: Optional[StrictBool] = Field(default=False, description="Display left pages menu?")
    displayleftif: Optional[StrictInt] = Field(default=0, description="Minimum grade to display menu")
    feedback: Optional[StrictBool] = Field(default=False, description="Display default feedback")
    grade: Optional[StrictInt] = Field(default=0, description="The total that the grade is scaled to be out of")
    height: Optional[StrictInt] = Field(default=0, description="Slideshow height")
    id: StrictInt = Field(description="Standard Moodle primary key.")
    intro: Optional[StrictStr] = Field(default='', description="Lesson introduction text.")
    introfiles: Optional[List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner]] = Field(default=None, description="introfiles")
    introformat: Optional[StrictInt] = Field(default=0, description="intro format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    lang: Optional[StrictStr] = Field(description="Forced activity language")
    maxanswers: Optional[StrictInt] = Field(default=0, description="Maximum answers per page")
    maxattempts: Optional[StrictInt] = Field(default=0, description="Maximum attempts")
    maxpages: Optional[StrictInt] = Field(default=0, description="Number of pages to show")
    mediaclose: Optional[StrictInt] = Field(default=0, description="Display a close button in the popup?")
    mediafile: Optional[StrictStr] = Field(default='', description="Local file path or full external URL")
    mediafiles: Optional[List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner]] = Field(default=None, description="mediafiles")
    mediaheight: Optional[StrictInt] = Field(default=0, description="Popup for media file height")
    mediawidth: Optional[StrictInt] = Field(default=0, description="Popup for media with")
    minquestions: Optional[StrictInt] = Field(default=0, description="Minimum number of questions")
    modattempts: Optional[StrictBool] = Field(default=False, description="Allow student review?")
    name: StrictStr = Field(description="Lesson name.")
    nextpagedefault: Optional[StrictInt] = Field(default=0, description="Action for a correct answer")
    ongoing: Optional[StrictBool] = Field(default=False, description="Display ongoing score?")
    password: Optional[StrictStr] = Field(default='', description="Password")
    practice: Optional[StrictBool] = Field(default=False, description="Practice lesson?")
    progressbar: Optional[StrictBool] = Field(default=False, description="Display progress bar?")
    retake: Optional[StrictBool] = Field(default=False, description="Re-takes allowed")
    review: Optional[StrictBool] = Field(default=False, description="Provide option to try a question again")
    slideshow: Optional[StrictBool] = Field(default=False, description="Display lesson as slideshow")
    timelimit: Optional[StrictInt] = Field(default=0, description="Time limit")
    timemodified: Optional[StrictInt] = Field(default=0, description="Last time settings were updated")
    usemaxgrade: Optional[StrictInt] = Field(default=0, description="How to calculate the final grade")
    usepassword: Optional[StrictBool] = Field(default=False, description="Password protected lesson?")
    width: Optional[StrictInt] = Field(default=0, description="Slideshow width")
    __properties: ClassVar[List[str]] = ["activitylink", "allowofflineattempts", "available", "bgcolor", "completionendreached", "completiontimespent", "conditions", "course", "coursemodule", "custom", "deadline", "dependency", "displayleft", "displayleftif", "feedback", "grade", "height", "id", "intro", "introfiles", "introformat", "lang", "maxanswers", "maxattempts", "maxpages", "mediaclose", "mediafile", "mediafiles", "mediaheight", "mediawidth", "minquestions", "modattempts", "name", "nextpagedefault", "ongoing", "password", "practice", "progressbar", "retake", "review", "slideshow", "timelimit", "timemodified", "usemaxgrade", "usepassword", "width"]

    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 ModLessonGetLessonResponseLesson 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 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 mediafiles (list)
        _items = []
        if self.mediafiles:
            for _item_mediafiles in self.mediafiles:
                if _item_mediafiles:
                    _items.append(_item_mediafiles.to_dict())
            _dict['mediafiles'] = _items
        # 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

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

        return _dict

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

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

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

        data = {
            "activitylink": obj.get("activitylink") if obj.get("activitylink") is not None else 0,
            "allowofflineattempts": obj.get("allowofflineattempts") if obj.get("allowofflineattempts") is not None else False,
            "available": obj.get("available") if obj.get("available") is not None else 0,
            "bgcolor": obj.get("bgcolor") if obj.get("bgcolor") is not None else '',
            "completionendreached": obj.get("completionendreached") if obj.get("completionendreached") is not None else 0,
            "completiontimespent": obj.get("completiontimespent") if obj.get("completiontimespent") is not None else 0,
            "conditions": obj.get("conditions") if obj.get("conditions") is not None else '',
            "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,
            "custom": obj.get("custom") if obj.get("custom") is not None else False,
            "deadline": obj.get("deadline") if obj.get("deadline") is not None else 0,
            "dependency": obj.get("dependency") if obj.get("dependency") is not None else 0,
            "displayleft": obj.get("displayleft") if obj.get("displayleft") is not None else False,
            "displayleftif": obj.get("displayleftif") if obj.get("displayleftif") is not None else 0,
            "feedback": obj.get("feedback") if obj.get("feedback") is not None else False,
            "grade": obj.get("grade") if obj.get("grade") is not None else 0,
            "height": obj.get("height") if obj.get("height") 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,
            "lang": obj.get("lang"),
            "maxanswers": obj.get("maxanswers") if obj.get("maxanswers") is not None else 0,
            "maxattempts": obj.get("maxattempts") if obj.get("maxattempts") is not None else 0,
            "maxpages": obj.get("maxpages") if obj.get("maxpages") is not None else 0,
            "mediaclose": obj.get("mediaclose") if obj.get("mediaclose") is not None else 0,
            "mediafile": obj.get("mediafile") if obj.get("mediafile") is not None else '',
            "mediafiles": [CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner.from_dict(_item) for _item in obj["mediafiles"]] if obj.get("mediafiles") is not None else None,
            "mediaheight": obj.get("mediaheight") if obj.get("mediaheight") is not None else 0,
            "mediawidth": obj.get("mediawidth") if obj.get("mediawidth") is not None else 0,
            "minquestions": obj.get("minquestions") if obj.get("minquestions") is not None else 0,
            "modattempts": obj.get("modattempts") if obj.get("modattempts") is not None else False,
            "name": obj.get("name") if obj.get("name") is not None else '',
            "nextpagedefault": obj.get("nextpagedefault") if obj.get("nextpagedefault") is not None else 0,
            "ongoing": obj.get("ongoing") if obj.get("ongoing") is not None else False,
            "password": obj.get("password") if obj.get("password") is not None else '',
            "practice": obj.get("practice") if obj.get("practice") is not None else False,
            "progressbar": obj.get("progressbar") if obj.get("progressbar") is not None else False,
            "retake": obj.get("retake") if obj.get("retake") is not None else False,
            "review": obj.get("review") if obj.get("review") is not None else False,
            "slideshow": obj.get("slideshow") if obj.get("slideshow") is not None else False,
            "timelimit": obj.get("timelimit") if obj.get("timelimit") is not None else 0,
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0,
            "usemaxgrade": obj.get("usemaxgrade") if obj.get("usemaxgrade") is not None else 0,
            "usepassword": obj.get("usepassword") if obj.get("usepassword") is not None else False,
            "width": obj.get("width") if obj.get("width") is not None else 0
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


