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

from poodle_async_full.configuration import settings

class CoreSearchGetResultsResponseResultsInner(BaseModel):
    """
    CoreSearchGetResultsResponseResultsInner
    """ # noqa: E501
    areaname: StrictStr = Field(description="search area name")
    componentname: StrictStr = Field(description="component name")
    content: Optional[StrictStr] = Field(default='', description="result contents")
    contextid: StrictInt = Field(description="result context id")
    contexturl: StrictStr = Field(description="result context url")
    coursefullname: StrictStr = Field(description="result course fullname")
    courseurl: StrictStr = Field(description="result course url")
    description1: Optional[StrictStr] = Field(default='', description="extra result contents, depends on the search area")
    description2: Optional[StrictStr] = Field(default='', description="extra result contents, depends on the search area")
    docurl: StrictStr = Field(description="result url")
    filename: Optional[StrictStr] = Field(default='', description="result file name if present")
    filenames: Optional[StrictStr] = Field(default='', description="result file names if present")
    iconurl: Optional[StrictStr] = Field(default='', description="icon url")
    itemid: StrictInt = Field(description="unique id in the search area scope")
    multiplefiles: Optional[StrictInt] = Field(default=0, description="whether multiple files are returned or not")
    textformat: StrictInt = Field(description="text fields format, it is the same for all of them")
    timemodified: StrictInt = Field(description="result modified time")
    title: StrictStr = Field(description="result title")
    userfullname: Optional[StrictStr] = Field(default='', description="user fullname")
    userid: Optional[StrictInt] = Field(default=0, description="user id")
    userurl: Optional[StrictStr] = Field(default='', description="user url")
    __properties: ClassVar[List[str]] = ["areaname", "componentname", "content", "contextid", "contexturl", "coursefullname", "courseurl", "description1", "description2", "docurl", "filename", "filenames", "iconurl", "itemid", "multiplefiles", "textformat", "timemodified", "title", "userfullname", "userid", "userurl"]

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

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

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

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

        return _dict

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

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

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

        data = {
            "areaname": obj.get("areaname") if obj.get("areaname") is not None else '',
            "componentname": obj.get("componentname") if obj.get("componentname") is not None else '',
            "content": obj.get("content") if obj.get("content") is not None else '',
            "contextid": obj.get("contextid") if obj.get("contextid") is not None else 0,
            "contexturl": obj.get("contexturl") if obj.get("contexturl") is not None else '',
            "coursefullname": obj.get("coursefullname") if obj.get("coursefullname") is not None else '',
            "courseurl": obj.get("courseurl") if obj.get("courseurl") is not None else '',
            "description1": obj.get("description1") if obj.get("description1") is not None else '',
            "description2": obj.get("description2") if obj.get("description2") is not None else '',
            "docurl": obj.get("docurl") if obj.get("docurl") is not None else '',
            "filename": obj.get("filename") if obj.get("filename") is not None else '',
            "filenames": obj.get("filenames") if obj.get("filenames") is not None else '',
            "iconurl": obj.get("iconurl") if obj.get("iconurl") is not None else '',
            "itemid": obj.get("itemid") if obj.get("itemid") is not None else 0,
            "multiplefiles": obj.get("multiplefiles") if obj.get("multiplefiles") is not None else 0,
            "textformat": obj.get("textformat") if obj.get("textformat") is not None else 0,
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0,
            "title": obj.get("title") if obj.get("title") is not None else '',
            "userfullname": obj.get("userfullname") if obj.get("userfullname") is not None else '',
            "userid": obj.get("userid") if obj.get("userid") is not None else 0,
            "userurl": obj.get("userurl") if obj.get("userurl") is not None else ''
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


