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

from poodle_async_full.configuration import settings

class ModGlossaryGetEntriesByAuthorIdResponseEntriesInner(BaseModel):
    """
    ModGlossaryGetEntriesByAuthorIdResponseEntriesInner
    """ # noqa: E501
    approved: Optional[StrictBool] = Field(description="Whether the entry was approved")
    attachment: Optional[StrictBool] = Field(description="Whether or not the entry has attachments")
    attachments: Optional[List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner]] = Field(default=None, description="attachments")
    casesensitive: Optional[StrictBool] = Field(description="When true, the matching is case sensitive")
    concept: Optional[StrictStr] = Field(description="The concept")
    definition: Optional[StrictStr] = Field(description="The definition")
    definitionformat: Optional[StrictInt] = Field(description="definition format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    definitioninlinefiles: Optional[List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner]] = Field(default=None, description="entry definition inline files")
    definitiontrust: Optional[StrictBool] = Field(description="The definition trust flag")
    fullmatch: Optional[StrictBool] = Field(description="When true, the matching is done on full words only")
    glossaryid: Optional[StrictInt] = Field(description="The glossary ID")
    id: Optional[StrictInt] = Field(description="The entry ID")
    sourceglossaryid: Optional[StrictInt] = Field(description="The source glossary ID")
    tags: Optional[List[CoreBlogGetEntriesResponseEntriesInnerTagsInner]] = Field(default=None, description="Tags")
    teacherentry: Optional[StrictBool] = Field(description="The entry was created by a teacher, or equivalent.")
    timecreated: Optional[StrictInt] = Field(description="Time created")
    timemodified: Optional[StrictInt] = Field(description="Time modified")
    usedynalink: Optional[StrictBool] = Field(description="Whether the concept should be automatically linked")
    userfullname: Optional[StrictStr] = Field(description="Author full name")
    userid: Optional[StrictInt] = Field(description="Author ID")
    userpictureurl: Optional[StrictStr] = Field(description="Author picture")
    __properties: ClassVar[List[str]] = ["approved", "attachment", "attachments", "casesensitive", "concept", "definition", "definitionformat", "definitioninlinefiles", "definitiontrust", "fullmatch", "glossaryid", "id", "sourceglossaryid", "tags", "teacherentry", "timecreated", "timemodified", "usedynalink", "userfullname", "userid", "userpictureurl"]

    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 ModGlossaryGetEntriesByAuthorIdResponseEntriesInner 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 attachments (list)
        _items = []
        if self.attachments:
            for _item_attachments in self.attachments:
                if _item_attachments:
                    _items.append(_item_attachments.to_dict())
            _dict['attachments'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in definitioninlinefiles (list)
        _items = []
        if self.definitioninlinefiles:
            for _item_definitioninlinefiles in self.definitioninlinefiles:
                if _item_definitioninlinefiles:
                    _items.append(_item_definitioninlinefiles.to_dict())
            _dict['definitioninlinefiles'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in tags (list)
        _items = []
        if self.tags:
            for _item_tags in self.tags:
                if _item_tags:
                    _items.append(_item_tags.to_dict())
            _dict['tags'] = _items
        # set to None if approved (nullable) is None
        # and model_fields_set contains the field
        if self.approved is None and "approved" in self.model_fields_set:
            _dict['approved'] = None

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "approved": obj.get("approved"),
            "attachment": obj.get("attachment"),
            "attachments": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["attachments"]] if obj.get("attachments") is not None else None,
            "casesensitive": obj.get("casesensitive"),
            "concept": obj.get("concept"),
            "definition": obj.get("definition"),
            "definitionformat": obj.get("definitionformat"),
            "definitioninlinefiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["definitioninlinefiles"]] if obj.get("definitioninlinefiles") is not None else None,
            "definitiontrust": obj.get("definitiontrust"),
            "fullmatch": obj.get("fullmatch"),
            "glossaryid": obj.get("glossaryid"),
            "id": obj.get("id"),
            "sourceglossaryid": obj.get("sourceglossaryid"),
            "tags": [CoreBlogGetEntriesResponseEntriesInnerTagsInner.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None,
            "teacherentry": obj.get("teacherentry"),
            "timecreated": obj.get("timecreated"),
            "timemodified": obj.get("timemodified"),
            "usedynalink": obj.get("usedynalink"),
            "userfullname": obj.get("userfullname"),
            "userid": obj.get("userid"),
            "userpictureurl": obj.get("userpictureurl")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


