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

from poodle_async_full.configuration import settings

class ModFeedbackGetFeedbacksByCoursesResponseFeedbacksInner(BaseModel):
    """
    ModFeedbackGetFeedbacksByCoursesResponseFeedbacksInner
    """ # noqa: E501
    anonymous: StrictInt = Field(description="Whether the feedback is anonymous.")
    autonumbering: StrictBool = Field(description="Whether questions should be auto-numbered.")
    completionsubmit: StrictBool = Field(description="If this field is set to 1, then the activity will be automatically marked as complete on submission.")
    course: StrictInt = Field(description="Course id this feedback is part of.")
    coursemodule: StrictInt = Field(description="coursemodule")
    email_notification: Optional[StrictBool] = Field(default=False, description="Whether email notifications will be sent to teachers.")
    id: StrictInt = Field(description="The primary key of the record.")
    intro: StrictStr = Field(description="Feedback introduction text.")
    introfiles: List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner] = Field(description="introfiles")
    introformat: Optional[StrictInt] = Field(default=0, description="intro format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    lang: Optional[StrictStr] = Field(description="Forced activity language")
    multiple_submit: StrictBool = Field(description="Whether multiple submissions are allowed.")
    name: StrictStr = Field(description="Feedback name.")
    page_after_submit: Optional[StrictStr] = Field(default='', description="Text to display after submission.")
    page_after_submitformat: Optional[StrictInt] = Field(default=0, description="page_after_submit format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    pageaftersubmitfiles: Optional[List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner]] = Field(default=None, description="pageaftersubmitfiles")
    publish_stats: StrictBool = Field(description="Whether stats should be published.")
    site_after_submit: Optional[StrictStr] = Field(default='', description="Link to next page after submission.")
    timeclose: Optional[StrictInt] = Field(default=0, description="Allow answers until this time.")
    timemodified: Optional[StrictInt] = Field(default=0, description="The time this record was modified.")
    timeopen: Optional[StrictInt] = Field(default=0, description="Allow answers from this time.")
    __properties: ClassVar[List[str]] = ["anonymous", "autonumbering", "completionsubmit", "course", "coursemodule", "email_notification", "id", "intro", "introfiles", "introformat", "lang", "multiple_submit", "name", "page_after_submit", "page_after_submitformat", "pageaftersubmitfiles", "publish_stats", "site_after_submit", "timeclose", "timemodified", "timeopen"]

    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 ModFeedbackGetFeedbacksByCoursesResponseFeedbacksInner 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
        # override the default output from pydantic by calling `to_dict()` of each item in pageaftersubmitfiles (list)
        _items = []
        if self.pageaftersubmitfiles:
            for _item_pageaftersubmitfiles in self.pageaftersubmitfiles:
                if _item_pageaftersubmitfiles:
                    _items.append(_item_pageaftersubmitfiles.to_dict())
            _dict['pageaftersubmitfiles'] = _items
        # 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 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 page_after_submitformat (nullable) is None
        # and model_fields_set contains the field
        if self.page_after_submitformat is None and "page_after_submitformat" in self.model_fields_set:
            _dict['page_after_submitformat'] = None

        return _dict

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

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

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

        data = {
            "anonymous": obj.get("anonymous") if obj.get("anonymous") is not None else 0,
            "autonumbering": obj.get("autonumbering") if obj.get("autonumbering") is not None else True,
            "completionsubmit": obj.get("completionsubmit") if obj.get("completionsubmit") is not None else False,
            "course": obj.get("course") if obj.get("course") is not None else 0,
            "coursemodule": obj.get("coursemodule") if obj.get("coursemodule") is not None else 0,
            "email_notification": obj.get("email_notification") if obj.get("email_notification") is not None else False,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "intro": obj.get("intro") if obj.get("intro") is not None else '',
            "introfiles": [CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner.from_dict(_item) for _item in obj["introfiles"]] if obj.get("introfiles") is not None else None,
            "introformat": obj.get("introformat") if obj.get("introformat") is not None else 0,
            "lang": obj.get("lang"),
            "multiple_submit": obj.get("multiple_submit") if obj.get("multiple_submit") is not None else True,
            "name": obj.get("name") if obj.get("name") is not None else '',
            "page_after_submit": obj.get("page_after_submit") if obj.get("page_after_submit") is not None else '',
            "page_after_submitformat": obj.get("page_after_submitformat") if obj.get("page_after_submitformat") is not None else 0,
            "pageaftersubmitfiles": [CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner.from_dict(_item) for _item in obj["pageaftersubmitfiles"]] if obj.get("pageaftersubmitfiles") is not None else None,
            "publish_stats": obj.get("publish_stats") if obj.get("publish_stats") is not None else False,
            "site_after_submit": obj.get("site_after_submit") if obj.get("site_after_submit") is not None else '',
            "timeclose": obj.get("timeclose") if obj.get("timeclose") is not None else 0,
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0,
            "timeopen": obj.get("timeopen") if obj.get("timeopen") is not None else 0
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


