# 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_cohort_create_cohorts_parameters_cohorts_inner_customfields_inner import CoreCohortCreateCohortsParametersCohortsInnerCustomfieldsInner
from poodle_async_full.models.core_course_create_courses_parameters_courses_inner_courseformatoptions_inner import CoreCourseCreateCoursesParametersCoursesInnerCourseformatoptionsInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreCourseCreateCoursesParametersCoursesInner(BaseModel):
    """
    CoreCourseCreateCoursesParametersCoursesInner
    """ # noqa: E501
    categoryid: Optional[StrictInt] = Field(description="category id")
    completionnotify: Optional[StrictInt] = Field(default=None, description="1: yes 0: no")
    courseformatoptions: Optional[List[CoreCourseCreateCoursesParametersCoursesInnerCourseformatoptionsInner]] = Field(default=None, description="additional options for particular course format")
    customfields: Optional[List[CoreCohortCreateCohortsParametersCohortsInnerCustomfieldsInner]] = Field(default=None, description="custom fields for the course")
    defaultgroupingid: Optional[StrictInt] = Field(default=0, description="default grouping id")
    enablecompletion: Optional[StrictInt] = Field(default=None, description="Enabled, control via completion and activity settings. Disabled,                                         not shown in activity settings.")
    enddate: Optional[StrictInt] = Field(default=None, description="timestamp when the course end")
    forcetheme: Optional[StrictStr] = Field(default=None, description="name of the force theme")
    format: Optional[StrictStr] = Field(default='topics', description="course format: weeks, topics, social, site,..")
    fullname: Optional[StrictStr] = Field(description="full name")
    groupmode: Optional[StrictInt] = Field(default=0, description="no group, separate, visible")
    groupmodeforce: Optional[StrictInt] = Field(default=0, description="1: yes, 0: no")
    hiddensections: Optional[StrictInt] = Field(default=None, description="(deprecated, use courseformatoptions) How the hidden sections in the course are displayed to students")
    idnumber: Optional[StrictStr] = Field(default=None, description="id number")
    lang: Optional[StrictStr] = Field(default=None, description="forced course language")
    maxbytes: Optional[StrictInt] = Field(default=0, description="largest size of file that can be uploaded into the course")
    newsitems: Optional[StrictInt] = Field(default=5, description="number of recent items appearing on the course page")
    numsections: Optional[StrictInt] = Field(default=None, description="(deprecated, use courseformatoptions) number of weeks/topics")
    shortname: Optional[StrictStr] = Field(description="course short name")
    showgrades: Optional[StrictInt] = Field(default=1, description="1 if grades are shown, otherwise 0")
    showreports: Optional[StrictInt] = Field(default=0, description="are activity report shown (yes = 1, no =0)")
    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=1, description="summary format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    visible: Optional[StrictInt] = Field(default=1, description="1: available to student, 0: not available")
    __properties: ClassVar[List[str]] = ["categoryid", "completionnotify", "courseformatoptions", "customfields", "defaultgroupingid", "enablecompletion", "enddate", "forcetheme", "format", "fullname", "groupmode", "groupmodeforce", "hiddensections", "idnumber", "lang", "maxbytes", "newsitems", "numsections", "shortname", "showgrades", "showreports", "startdate", "summary", "summaryformat", "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 CoreCourseCreateCoursesParametersCoursesInner 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 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
        # 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 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 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 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 forcetheme (nullable) is None
        # and model_fields_set contains the field
        if self.forcetheme is None and "forcetheme" in self.model_fields_set:
            _dict['forcetheme'] = 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 hiddensections (nullable) is None
        # and model_fields_set contains the field
        if self.hiddensections is None and "hiddensections" in self.model_fields_set:
            _dict['hiddensections'] = 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 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 numsections (nullable) is None
        # and model_fields_set contains the field
        if self.numsections is None and "numsections" in self.model_fields_set:
            _dict['numsections'] = 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 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 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 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 CoreCourseCreateCoursesParametersCoursesInner from a dict"""
        if obj is None:
            return None

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

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

        data = {
            "categoryid": obj.get("categoryid"),
            "completionnotify": obj.get("completionnotify"),
            "courseformatoptions": [CoreCourseCreateCoursesParametersCoursesInnerCourseformatoptionsInner.from_dict(_item) for _item in obj["courseformatoptions"]] if obj.get("courseformatoptions") is not None else None,
            "customfields": [CoreCohortCreateCohortsParametersCohortsInnerCustomfieldsInner.from_dict(_item) for _item in obj["customfields"]] if obj.get("customfields") is not None else None,
            "defaultgroupingid": obj.get("defaultgroupingid") if obj.get("defaultgroupingid") is not None else 0,
            "enablecompletion": obj.get("enablecompletion"),
            "enddate": obj.get("enddate"),
            "forcetheme": obj.get("forcetheme"),
            "format": obj.get("format") if obj.get("format") is not None else 'topics',
            "fullname": obj.get("fullname"),
            "groupmode": obj.get("groupmode") if obj.get("groupmode") is not None else 0,
            "groupmodeforce": obj.get("groupmodeforce") if obj.get("groupmodeforce") is not None else 0,
            "hiddensections": obj.get("hiddensections"),
            "idnumber": obj.get("idnumber"),
            "lang": obj.get("lang"),
            "maxbytes": obj.get("maxbytes") if obj.get("maxbytes") is not None else 0,
            "newsitems": obj.get("newsitems") if obj.get("newsitems") is not None else 5,
            "numsections": obj.get("numsections"),
            "shortname": obj.get("shortname"),
            "showgrades": obj.get("showgrades") if obj.get("showgrades") is not None else 1,
            "showreports": obj.get("showreports") if obj.get("showreports") is not None else 0,
            "startdate": obj.get("startdate"),
            "summary": obj.get("summary"),
            "summaryformat": obj.get("summaryformat") if obj.get("summaryformat") is not None else 1,
            "visible": obj.get("visible") if obj.get("visible") is not None else 1
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


