# 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 ModDataGetDatabasesByCoursesResponseDatabasesInner(BaseModel):
    """
    ModDataGetDatabasesByCoursesResponseDatabasesInner
    """ # noqa: E501
    addtemplate: Optional[StrictStr] = Field(description="addtemplate field")
    approval: StrictBool = Field(description="approval field")
    asearchtemplate: Optional[StrictStr] = Field(description="asearchtemplate field")
    assessed: Optional[StrictInt] = Field(default=0, description="assessed field")
    assesstimefinish: Optional[StrictInt] = Field(default=0, description="assesstimefinish field")
    assesstimestart: Optional[StrictInt] = Field(default=0, description="assesstimestart field")
    comments: StrictBool = Field(description="comments enabled")
    course: StrictInt = Field(description="Course id")
    coursemodule: StrictInt = Field(description="coursemodule")
    csstemplate: Optional[StrictStr] = Field(description="csstemplate field")
    defaultsort: StrictInt = Field(description="defaultsort field")
    defaultsortdir: StrictInt = Field(description="defaultsortdir field")
    editany: Optional[StrictBool] = Field(default=False, description="editany field (not used any more)")
    id: StrictInt = Field(description="Database id")
    intro: StrictStr = Field(description="The Database intro")
    introfiles: Optional[List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner]] = Field(default=None, description="introfiles")
    introformat: Optional[StrictInt] = Field(default=0, description="intro format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    jstemplate: Optional[StrictStr] = Field(description="jstemplate field")
    lang: Optional[StrictStr] = Field(description="Forced activity language")
    listtemplate: Optional[StrictStr] = Field(description="listtemplate field")
    listtemplatefooter: Optional[StrictStr] = Field(description="listtemplatefooter field")
    listtemplateheader: Optional[StrictStr] = Field(description="listtemplateheader field")
    manageapproved: StrictBool = Field(description="manageapproved field")
    maxentries: StrictInt = Field(description="maxentries field")
    name: StrictStr = Field(description="Database name")
    notification: Optional[StrictInt] = Field(default=0, description="notification field (not used any more)")
    requiredentries: StrictInt = Field(description="requiredentries field")
    requiredentriestoview: StrictInt = Field(description="requiredentriestoview field")
    rssarticles: StrictInt = Field(description="rssarticles field")
    rsstemplate: Optional[StrictStr] = Field(description="rsstemplate field")
    rsstitletemplate: Optional[StrictStr] = Field(description="rsstitletemplate field")
    scale: Optional[StrictInt] = Field(default=0, description="scale field")
    singletemplate: Optional[StrictStr] = Field(description="singletemplate field")
    timeavailablefrom: StrictInt = Field(description="timeavailablefrom field")
    timeavailableto: StrictInt = Field(description="timeavailableto field")
    timemodified: Optional[StrictInt] = Field(default=0, description="Time modified")
    timeviewfrom: StrictInt = Field(description="timeviewfrom field")
    timeviewto: StrictInt = Field(description="timeviewto field")
    __properties: ClassVar[List[str]] = ["addtemplate", "approval", "asearchtemplate", "assessed", "assesstimefinish", "assesstimestart", "comments", "course", "coursemodule", "csstemplate", "defaultsort", "defaultsortdir", "editany", "id", "intro", "introfiles", "introformat", "jstemplate", "lang", "listtemplate", "listtemplatefooter", "listtemplateheader", "manageapproved", "maxentries", "name", "notification", "requiredentries", "requiredentriestoview", "rssarticles", "rsstemplate", "rsstitletemplate", "scale", "singletemplate", "timeavailablefrom", "timeavailableto", "timemodified", "timeviewfrom", "timeviewto"]

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "addtemplate": obj.get("addtemplate"),
            "approval": obj.get("approval") if obj.get("approval") is not None else False,
            "asearchtemplate": obj.get("asearchtemplate"),
            "assessed": obj.get("assessed") if obj.get("assessed") is not None else 0,
            "assesstimefinish": obj.get("assesstimefinish") if obj.get("assesstimefinish") is not None else 0,
            "assesstimestart": obj.get("assesstimestart") if obj.get("assesstimestart") is not None else 0,
            "comments": obj.get("comments") if obj.get("comments") 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,
            "csstemplate": obj.get("csstemplate"),
            "defaultsort": obj.get("defaultsort") if obj.get("defaultsort") is not None else 0,
            "defaultsortdir": obj.get("defaultsortdir") if obj.get("defaultsortdir") is not None else 0,
            "editany": obj.get("editany") if obj.get("editany") 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,
            "jstemplate": obj.get("jstemplate"),
            "lang": obj.get("lang"),
            "listtemplate": obj.get("listtemplate"),
            "listtemplatefooter": obj.get("listtemplatefooter"),
            "listtemplateheader": obj.get("listtemplateheader"),
            "manageapproved": obj.get("manageapproved") if obj.get("manageapproved") is not None else False,
            "maxentries": obj.get("maxentries") if obj.get("maxentries") is not None else 0,
            "name": obj.get("name") if obj.get("name") is not None else '',
            "notification": obj.get("notification") if obj.get("notification") is not None else 0,
            "requiredentries": obj.get("requiredentries") if obj.get("requiredentries") is not None else 0,
            "requiredentriestoview": obj.get("requiredentriestoview") if obj.get("requiredentriestoview") is not None else 0,
            "rssarticles": obj.get("rssarticles") if obj.get("rssarticles") is not None else 0,
            "rsstemplate": obj.get("rsstemplate"),
            "rsstitletemplate": obj.get("rsstitletemplate"),
            "scale": obj.get("scale") if obj.get("scale") is not None else 0,
            "singletemplate": obj.get("singletemplate"),
            "timeavailablefrom": obj.get("timeavailablefrom") if obj.get("timeavailablefrom") is not None else 0,
            "timeavailableto": obj.get("timeavailableto") if obj.get("timeavailableto") is not None else 0,
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0,
            "timeviewfrom": obj.get("timeviewfrom") if obj.get("timeviewfrom") is not None else 0,
            "timeviewto": obj.get("timeviewto") if obj.get("timeviewto") is not None else 0
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


