# 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_block_get_course_blocks_response_blocks_inner_contents_files_inner import CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner
from poodle_async_full.models.core_cohort_get_cohorts_response_inner_customfields_inner import CoreCohortGetCohortsResponseInnerCustomfieldsInner
from poodle_async_full.models.core_course_get_courses_by_field_response_courses_inner_contacts_inner import CoreCourseGetCoursesByFieldResponseCoursesInnerContactsInner
from poodle_async_full.models.core_course_get_courses_by_field_response_courses_inner_courseformatoptions_inner import CoreCourseGetCoursesByFieldResponseCoursesInnerCourseformatoptionsInner
from poodle_async_full.models.core_course_get_courses_by_field_response_courses_inner_filters_inner import CoreCourseGetCoursesByFieldResponseCoursesInnerFiltersInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreCourseGetCoursesByFieldResponseCoursesInner(BaseModel):
    """
    CoreCourseGetCoursesByFieldResponseCoursesInner
    """ # noqa: E501
    cacherev: Optional[StrictInt] = Field(default=None, description="Cache revision number")
    calendartype: Optional[StrictStr] = Field(default=None, description="Calendar type")
    categoryid: Optional[StrictInt] = Field(description="category id")
    categoryname: Optional[StrictStr] = Field(description="category name")
    communicationroomname: Optional[StrictStr] = Field(default=None, description="Communication tool room name.")
    communicationroomurl: Optional[StrictStr] = Field(default=None, description="Communication tool room URL.")
    completionnotify: Optional[StrictInt] = Field(default=None, description="1: yes 0: no")
    contacts: List[CoreCourseGetCoursesByFieldResponseCoursesInnerContactsInner] = Field(description="contact users")
    courseformatoptions: Optional[List[CoreCourseGetCoursesByFieldResponseCoursesInnerCourseformatoptionsInner]] = Field(default=None, description="Additional options for particular course format.")
    courseimage: Optional[StrictStr] = Field(default=None, description="Course image")
    customfields: Optional[List[CoreCohortGetCohortsResponseInnerCustomfieldsInner]] = Field(default=None, description="Custom fields")
    defaultgroupingid: Optional[StrictInt] = Field(default=None, description="default grouping id")
    displayname: Optional[StrictStr] = Field(description="course display name")
    enablecompletion: Optional[StrictInt] = Field(default=None, description="Completion enabled? 1: yes 0: no")
    enddate: Optional[StrictInt] = Field(default=None, description="Timestamp when the course end")
    enrollmentmethods: List[Optional[StrictStr]] = Field(description="enrollment methods list")
    filters: Optional[List[CoreCourseGetCoursesByFieldResponseCoursesInnerFiltersInner]] = Field(default=None, description="Course filters")
    format: Optional[StrictStr] = Field(default=None, description="Course format: weeks, topics, social, site,..")
    fullname: Optional[StrictStr] = Field(description="course full name")
    groupmode: Optional[StrictInt] = Field(default=None, description="no group, separate, visible")
    groupmodeforce: Optional[StrictInt] = Field(default=None, description="1: yes, 0: no")
    id: Optional[StrictInt] = Field(description="course id")
    idnumber: Optional[StrictStr] = Field(default=None, description="Id number")
    lang: Optional[StrictStr] = Field(default=None, description="Forced course language")
    legacyfiles: Optional[StrictInt] = Field(default=None, description="If legacy files are enabled")
    marker: Optional[StrictInt] = Field(default=None, description="Current course marker")
    maxbytes: Optional[StrictInt] = Field(default=None, description="Largest size of file that can be uploaded into")
    newsitems: Optional[StrictInt] = Field(default=None, description="Number of recent items appearing on the course page")
    overviewfiles: List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner] = Field(description="additional overview files attached to this course")
    requested: Optional[StrictInt] = Field(default=None, description="If is a requested course")
    shortname: Optional[StrictStr] = Field(description="course short name")
    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[StrictInt] = Field(default=None, description="1 if grades are shown, otherwise 0")
    showreports: Optional[StrictInt] = Field(default=None, description="Are activity report shown (yes = 1, no =0)")
    sortorder: Optional[StrictInt] = Field(default=None, description="Sort order in the category")
    startdate: Optional[StrictInt] = Field(default=None, description="Timestamp when the course start")
    summary: Optional[StrictStr] = Field(description="summary")
    summaryfiles: Optional[List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner]] = Field(default=None, description="summary files in the summary field")
    summaryformat: Optional[StrictInt] = Field(description="summary format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    theme: Optional[StrictStr] = Field(default=None, description="Fame of the forced theme")
    timecreated: Optional[StrictInt] = Field(default=None, description="Time when the course was created")
    timemodified: Optional[StrictInt] = Field(default=None, description="Last time  the course was updated")
    visible: Optional[StrictInt] = Field(default=None, description="1: available to student, 0:not available")
    __properties: ClassVar[List[str]] = ["cacherev", "calendartype", "categoryid", "categoryname", "communicationroomname", "communicationroomurl", "completionnotify", "contacts", "courseformatoptions", "courseimage", "customfields", "defaultgroupingid", "displayname", "enablecompletion", "enddate", "enrollmentmethods", "filters", "format", "fullname", "groupmode", "groupmodeforce", "id", "idnumber", "lang", "legacyfiles", "marker", "maxbytes", "newsitems", "overviewfiles", "requested", "shortname", "showactivitydates", "showcompletionconditions", "showgrades", "showreports", "sortorder", "startdate", "summary", "summaryfiles", "summaryformat", "theme", "timecreated", "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 CoreCourseGetCoursesByFieldResponseCoursesInner 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 contacts (list)
        _items = []
        if self.contacts:
            for _item_contacts in self.contacts:
                if _item_contacts:
                    _items.append(_item_contacts.to_dict())
            _dict['contacts'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in courseformatoptions (list)
        _items = []
        if self.courseformatoptions:
            for _item_courseformatoptions in self.courseformatoptions:
                if _item_courseformatoptions:
                    _items.append(_item_courseformatoptions.to_dict())
            _dict['courseformatoptions'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in customfields (list)
        _items = []
        if self.customfields:
            for _item_customfields in self.customfields:
                if _item_customfields:
                    _items.append(_item_customfields.to_dict())
            _dict['customfields'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in filters (list)
        _items = []
        if self.filters:
            for _item_filters in self.filters:
                if _item_filters:
                    _items.append(_item_filters.to_dict())
            _dict['filters'] = _items
        # 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
        # override the default output from pydantic by calling `to_dict()` of each item in summaryfiles (list)
        _items = []
        if self.summaryfiles:
            for _item_summaryfiles in self.summaryfiles:
                if _item_summaryfiles:
                    _items.append(_item_summaryfiles.to_dict())
            _dict['summaryfiles'] = _items
        # set to None if cacherev (nullable) is None
        # and model_fields_set contains the field
        if self.cacherev is None and "cacherev" in self.model_fields_set:
            _dict['cacherev'] = None

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

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

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

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

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

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

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

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

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

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

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

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

        data = {
            "cacherev": obj.get("cacherev"),
            "calendartype": obj.get("calendartype"),
            "categoryid": obj.get("categoryid"),
            "categoryname": obj.get("categoryname"),
            "communicationroomname": obj.get("communicationroomname"),
            "communicationroomurl": obj.get("communicationroomurl"),
            "completionnotify": obj.get("completionnotify"),
            "contacts": [CoreCourseGetCoursesByFieldResponseCoursesInnerContactsInner.from_dict(_item) for _item in obj["contacts"]] if obj.get("contacts") is not None else None,
            "courseformatoptions": [CoreCourseGetCoursesByFieldResponseCoursesInnerCourseformatoptionsInner.from_dict(_item) for _item in obj["courseformatoptions"]] if obj.get("courseformatoptions") is not None else None,
            "courseimage": obj.get("courseimage"),
            "customfields": [CoreCohortGetCohortsResponseInnerCustomfieldsInner.from_dict(_item) for _item in obj["customfields"]] if obj.get("customfields") is not None else None,
            "defaultgroupingid": obj.get("defaultgroupingid"),
            "displayname": obj.get("displayname"),
            "enablecompletion": obj.get("enablecompletion"),
            "enddate": obj.get("enddate"),
            "enrollmentmethods": obj.get("enrollmentmethods"),
            "filters": [CoreCourseGetCoursesByFieldResponseCoursesInnerFiltersInner.from_dict(_item) for _item in obj["filters"]] if obj.get("filters") is not None else None,
            "format": obj.get("format"),
            "fullname": obj.get("fullname"),
            "groupmode": obj.get("groupmode"),
            "groupmodeforce": obj.get("groupmodeforce"),
            "id": obj.get("id"),
            "idnumber": obj.get("idnumber"),
            "lang": obj.get("lang"),
            "legacyfiles": obj.get("legacyfiles"),
            "marker": obj.get("marker"),
            "maxbytes": obj.get("maxbytes"),
            "newsitems": obj.get("newsitems"),
            "overviewfiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["overviewfiles"]] if obj.get("overviewfiles") is not None else None,
            "requested": obj.get("requested"),
            "shortname": obj.get("shortname"),
            "showactivitydates": obj.get("showactivitydates"),
            "showcompletionconditions": obj.get("showcompletionconditions"),
            "showgrades": obj.get("showgrades"),
            "showreports": obj.get("showreports"),
            "sortorder": obj.get("sortorder"),
            "startdate": obj.get("startdate"),
            "summary": obj.get("summary"),
            "summaryfiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["summaryfiles"]] if obj.get("summaryfiles") is not None else None,
            "summaryformat": obj.get("summaryformat"),
            "theme": obj.get("theme"),
            "timecreated": obj.get("timecreated"),
            "timemodified": obj.get("timemodified"),
            "visible": obj.get("visible")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


