# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from poodle_async_full.models.core_course_get_course_module_by_instance_response_cm_advancedgrading_inner import CoreCourseGetCourseModuleByInstanceResponseCmAdvancedgradingInner
from poodle_async_full.models.core_course_get_course_module_by_instance_response_cm_outcomes_inner import CoreCourseGetCourseModuleByInstanceResponseCmOutcomesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreCourseGetCourseModuleByInstanceResponseCm(BaseModel):
    """
    CoreCourseGetCourseModuleByInstanceResponseCm
    """ # noqa: E501
    added: Optional[StrictInt] = Field(default=None, description="Time added")
    advancedgrading: Optional[List[CoreCourseGetCourseModuleByInstanceResponseCmAdvancedgradingInner]] = Field(default=None, description="Advanced grading settings")
    availability: Optional[StrictStr] = Field(default=None, description="Availability settings")
    completion: Optional[StrictInt] = Field(description="If completion is enabled")
    completionexpected: Optional[StrictInt] = Field(default=None, description="Completion time expected")
    completiongradeitemnumber: Optional[StrictInt] = Field(default=None, description="Completion grade item")
    completionpassgrade: Optional[StrictInt] = Field(default=None, description="Completion pass grade setting")
    completionview: Optional[StrictInt] = Field(default=None, description="Completion view setting")
    course: Optional[StrictInt] = Field(description="The course id")
    downloadcontent: Optional[StrictInt] = Field(default=None, description="The download content value")
    grade: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Grade (max value or scale id)")
    gradecat: Optional[StrictInt] = Field(default=None, description="Grade category")
    gradepass: Optional[StrictStr] = Field(default=None, description="Grade to pass (float)")
    groupingid: Optional[StrictInt] = Field(description="Grouping id")
    groupmode: Optional[StrictInt] = Field(description="Group mode")
    id: Optional[StrictInt] = Field(description="The course module id")
    idnumber: Optional[StrictStr] = Field(default=None, description="Module id number")
    indent: Optional[StrictInt] = Field(default=None, description="Indentation")
    instance: Optional[StrictInt] = Field(description="The activity instance id")
    modname: Optional[StrictStr] = Field(description="The module component name (forum, assign, etc..)")
    module: Optional[StrictInt] = Field(description="The module type id")
    name: Optional[StrictStr] = Field(description="The activity name")
    outcomes: Optional[List[CoreCourseGetCourseModuleByInstanceResponseCmOutcomesInner]] = Field(default=None, description="Outcomes information")
    scale: Optional[StrictStr] = Field(default=None, description="Scale items (if used)")
    score: Optional[StrictInt] = Field(default=None, description="Score")
    section: Optional[StrictInt] = Field(description="The module section id")
    sectionnum: Optional[StrictInt] = Field(description="The module section number")
    showdescription: Optional[StrictInt] = Field(default=None, description="If the description is showed")
    visible: Optional[StrictInt] = Field(default=None, description="If visible")
    visibleold: Optional[StrictInt] = Field(default=None, description="Visible old")
    visibleoncoursepage: Optional[StrictInt] = Field(default=None, description="If visible on course page")
    __properties: ClassVar[List[str]] = ["added", "advancedgrading", "availability", "completion", "completionexpected", "completiongradeitemnumber", "completionpassgrade", "completionview", "course", "downloadcontent", "grade", "gradecat", "gradepass", "groupingid", "groupmode", "id", "idnumber", "indent", "instance", "modname", "module", "name", "outcomes", "scale", "score", "section", "sectionnum", "showdescription", "visible", "visibleold", "visibleoncoursepage"]

    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 CoreCourseGetCourseModuleByInstanceResponseCm 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 advancedgrading (list)
        _items = []
        if self.advancedgrading:
            for _item_advancedgrading in self.advancedgrading:
                if _item_advancedgrading:
                    _items.append(_item_advancedgrading.to_dict())
            _dict['advancedgrading'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in outcomes (list)
        _items = []
        if self.outcomes:
            for _item_outcomes in self.outcomes:
                if _item_outcomes:
                    _items.append(_item_outcomes.to_dict())
            _dict['outcomes'] = _items
        # set to None if added (nullable) is None
        # and model_fields_set contains the field
        if self.added is None and "added" in self.model_fields_set:
            _dict['added'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "added": obj.get("added"),
            "advancedgrading": [CoreCourseGetCourseModuleByInstanceResponseCmAdvancedgradingInner.from_dict(_item) for _item in obj["advancedgrading"]] if obj.get("advancedgrading") is not None else None,
            "availability": obj.get("availability"),
            "completion": obj.get("completion"),
            "completionexpected": obj.get("completionexpected"),
            "completiongradeitemnumber": obj.get("completiongradeitemnumber"),
            "completionpassgrade": obj.get("completionpassgrade"),
            "completionview": obj.get("completionview"),
            "course": obj.get("course"),
            "downloadcontent": obj.get("downloadcontent"),
            "grade": obj.get("grade"),
            "gradecat": obj.get("gradecat"),
            "gradepass": obj.get("gradepass"),
            "groupingid": obj.get("groupingid"),
            "groupmode": obj.get("groupmode"),
            "id": obj.get("id"),
            "idnumber": obj.get("idnumber"),
            "indent": obj.get("indent"),
            "instance": obj.get("instance"),
            "modname": obj.get("modname"),
            "module": obj.get("module"),
            "name": obj.get("name"),
            "outcomes": [CoreCourseGetCourseModuleByInstanceResponseCmOutcomesInner.from_dict(_item) for _item in obj["outcomes"]] if obj.get("outcomes") is not None else None,
            "scale": obj.get("scale"),
            "score": obj.get("score"),
            "section": obj.get("section"),
            "sectionnum": obj.get("sectionnum"),
            "showdescription": obj.get("showdescription"),
            "visible": obj.get("visible"),
            "visibleold": obj.get("visibleold"),
            "visibleoncoursepage": obj.get("visibleoncoursepage")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


