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

from poodle_async_full.configuration import settings

class ModForumGetForumsByCoursesResponseInner(BaseModel):
    """
    forum
    """ # noqa: E501
    assessed: Optional[StrictInt] = Field(description="Aggregate type")
    assesstimefinish: Optional[StrictInt] = Field(description="Assess finish time")
    assesstimestart: Optional[StrictInt] = Field(description="Assess start time")
    blockafter: Optional[StrictInt] = Field(description="Post threshold for blocking")
    blockperiod: Optional[StrictInt] = Field(description="Time period for blocking")
    cancreatediscussions: Optional[StrictBool] = Field(default=None, description="If the user can create discussions")
    cmid: Optional[StrictInt] = Field(description="Course module id")
    completiondiscussions: Optional[StrictInt] = Field(description="Student must create discussions")
    completionposts: Optional[StrictInt] = Field(description="Student must post discussions or replies")
    completionreplies: Optional[StrictInt] = Field(description="Student must post replies")
    course: Optional[StrictInt] = Field(description="Course id")
    cutoffdate: Optional[StrictInt] = Field(default=None, description="cutoffdate for the user")
    duedate: Optional[StrictInt] = Field(default=None, description="duedate for the user")
    forcesubscribe: Optional[StrictInt] = Field(description="Force users to subscribe")
    grade_forum: Optional[StrictInt] = Field(description="Whole forum grade")
    grade_forum_notify: Optional[StrictInt] = Field(description="Whether to send notifications to students upon grading by default")
    id: Optional[StrictInt] = Field(description="Forum id")
    intro: Optional[StrictStr] = Field(description="The forum intro")
    introfiles: Optional[List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner]] = Field(default=None, description="Files in the introduction text")
    introformat: Optional[StrictInt] = Field(description="intro format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    istracked: Optional[StrictBool] = Field(default=None, description="If the user is tracking the forum")
    lang: Optional[StrictStr] = Field(default=None, description="Forced activity language")
    lockdiscussionafter: Optional[StrictInt] = Field(default=None, description="After what period a discussion is locked")
    maxattachments: Optional[StrictInt] = Field(description="Maximum number of attachments")
    maxbytes: Optional[StrictInt] = Field(description="Maximum attachment size")
    name: Optional[StrictStr] = Field(description="Forum name")
    numdiscussions: Optional[StrictInt] = Field(default=None, description="Number of discussions in the forum")
    rssarticles: Optional[StrictInt] = Field(description="Number of RSS recent articles")
    rsstype: Optional[StrictInt] = Field(description="RSS feed for this activity")
    scale: Optional[StrictInt] = Field(description="Scale")
    timemodified: Optional[StrictInt] = Field(description="Time modified")
    trackingtype: Optional[StrictInt] = Field(description="Subscription mode")
    type: Optional[StrictStr] = Field(description="The forum type")
    unreadpostscount: Optional[StrictInt] = Field(default=None, description="The number of unread posts for tracked forums")
    warnafter: Optional[StrictInt] = Field(description="Post threshold for warning")
    __properties: ClassVar[List[str]] = ["assessed", "assesstimefinish", "assesstimestart", "blockafter", "blockperiod", "cancreatediscussions", "cmid", "completiondiscussions", "completionposts", "completionreplies", "course", "cutoffdate", "duedate", "forcesubscribe", "grade_forum", "grade_forum_notify", "id", "intro", "introfiles", "introformat", "istracked", "lang", "lockdiscussionafter", "maxattachments", "maxbytes", "name", "numdiscussions", "rssarticles", "rsstype", "scale", "timemodified", "trackingtype", "type", "unreadpostscount", "warnafter"]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "assessed": obj.get("assessed"),
            "assesstimefinish": obj.get("assesstimefinish"),
            "assesstimestart": obj.get("assesstimestart"),
            "blockafter": obj.get("blockafter"),
            "blockperiod": obj.get("blockperiod"),
            "cancreatediscussions": obj.get("cancreatediscussions"),
            "cmid": obj.get("cmid"),
            "completiondiscussions": obj.get("completiondiscussions"),
            "completionposts": obj.get("completionposts"),
            "completionreplies": obj.get("completionreplies"),
            "course": obj.get("course"),
            "cutoffdate": obj.get("cutoffdate"),
            "duedate": obj.get("duedate"),
            "forcesubscribe": obj.get("forcesubscribe"),
            "grade_forum": obj.get("grade_forum"),
            "grade_forum_notify": obj.get("grade_forum_notify"),
            "id": obj.get("id"),
            "intro": obj.get("intro"),
            "introfiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["introfiles"]] if obj.get("introfiles") is not None else None,
            "introformat": obj.get("introformat"),
            "istracked": obj.get("istracked"),
            "lang": obj.get("lang"),
            "lockdiscussionafter": obj.get("lockdiscussionafter"),
            "maxattachments": obj.get("maxattachments"),
            "maxbytes": obj.get("maxbytes"),
            "name": obj.get("name"),
            "numdiscussions": obj.get("numdiscussions"),
            "rssarticles": obj.get("rssarticles"),
            "rsstype": obj.get("rsstype"),
            "scale": obj.get("scale"),
            "timemodified": obj.get("timemodified"),
            "trackingtype": obj.get("trackingtype"),
            "type": obj.get("type"),
            "unreadpostscount": obj.get("unreadpostscount"),
            "warnafter": obj.get("warnafter")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


