# 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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from poodle_async_full.models.core_block_get_course_blocks_response_blocks_inner_contents_files_inner import CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreEnrolGetUsersCoursesResponseInner(BaseModel):
    """
    CoreEnrolGetUsersCoursesResponseInner
    """ # noqa: E501
    category: Optional[StrictInt] = Field(default=None, description="course category id")
    completed: Optional[StrictBool] = Field(default=None, description="Whether the course is completed.")
    completionhascriteria: Optional[StrictBool] = Field(default=None, description="If completion criteria is set.")
    completionusertracked: Optional[StrictBool] = Field(default=None, description="If the user is completion tracked.")
    courseimage: Optional[StrictStr] = Field(default=None, description="The course image URL")
    displayname: Optional[StrictStr] = Field(default=None, description="course display name for lists.")
    enablecompletion: Optional[StrictBool] = Field(default=None, description="true if completion is enabled, otherwise false")
    enddate: Optional[StrictInt] = Field(default=None, description="Timestamp when the course end")
    enrolledusercount: Optional[StrictInt] = Field(default=None, description="Number of enrolled users in this course")
    format: Optional[StrictStr] = Field(default=None, description="course format: weeks, topics, social, site")
    fullname: Optional[StrictStr] = Field(description="long name of course")
    hidden: Optional[StrictBool] = Field(default=None, description="If the user hide the course from the dashboard.")
    id: Optional[StrictInt] = Field(description="id of course")
    idnumber: Optional[StrictStr] = Field(description="id number of course")
    isfavourite: Optional[StrictBool] = Field(default=None, description="If the user marked this course a favourite.")
    lang: Optional[StrictStr] = Field(default=None, description="forced course language")
    lastaccess: Optional[StrictInt] = Field(default=None, description="Last access to the course (timestamp).")
    marker: Optional[StrictInt] = Field(default=None, description="Course section marker.")
    overviewfiles: Optional[List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner]] = Field(default=None, description="Overview files attached to this course.")
    progress: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Progress percentage")
    shortname: Optional[StrictStr] = Field(description="short name of course")
    showactivitydates: Optional[StrictBool] = Field(description="Whether the activity dates are shown or not")
    showcompletionconditions: Optional[StrictBool] = Field(description="Whether the activity completion conditions are shown or not")
    showgrades: Optional[StrictBool] = Field(default=None, description="true if grades are shown, otherwise false")
    startdate: Optional[StrictInt] = Field(default=None, description="Timestamp when the course start")
    summary: Optional[StrictStr] = Field(default=None, description="summary")
    summaryformat: Optional[StrictInt] = Field(default=None, description="summary format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    timemodified: Optional[StrictInt] = Field(default=None, description="Last time course settings were updated (timestamp).")
    visible: Optional[StrictInt] = Field(description="1 means visible, 0 means not yet visible course")
    __properties: ClassVar[List[str]] = ["category", "completed", "completionhascriteria", "completionusertracked", "courseimage", "displayname", "enablecompletion", "enddate", "enrolledusercount", "format", "fullname", "hidden", "id", "idnumber", "isfavourite", "lang", "lastaccess", "marker", "overviewfiles", "progress", "shortname", "showactivitydates", "showcompletionconditions", "showgrades", "startdate", "summary", "summaryformat", "timemodified", "visible"]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "category": obj.get("category"),
            "completed": obj.get("completed"),
            "completionhascriteria": obj.get("completionhascriteria"),
            "completionusertracked": obj.get("completionusertracked"),
            "courseimage": obj.get("courseimage"),
            "displayname": obj.get("displayname"),
            "enablecompletion": obj.get("enablecompletion"),
            "enddate": obj.get("enddate"),
            "enrolledusercount": obj.get("enrolledusercount"),
            "format": obj.get("format"),
            "fullname": obj.get("fullname"),
            "hidden": obj.get("hidden"),
            "id": obj.get("id"),
            "idnumber": obj.get("idnumber"),
            "isfavourite": obj.get("isfavourite"),
            "lang": obj.get("lang"),
            "lastaccess": obj.get("lastaccess"),
            "marker": obj.get("marker"),
            "overviewfiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["overviewfiles"]] if obj.get("overviewfiles") is not None else None,
            "progress": obj.get("progress"),
            "shortname": obj.get("shortname"),
            "showactivitydates": obj.get("showactivitydates"),
            "showcompletionconditions": obj.get("showcompletionconditions"),
            "showgrades": obj.get("showgrades"),
            "startdate": obj.get("startdate"),
            "summary": obj.get("summary"),
            "summaryformat": obj.get("summaryformat"),
            "timemodified": obj.get("timemodified"),
            "visible": obj.get("visible")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


