# 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 CoreMessageGetMessagesResponseMessagesInner(BaseModel):
    """
    message
    """ # noqa: E501
    component: Optional[StrictStr] = Field(default=None, description="The component that generated the notification")
    contexturl: Optional[StrictStr] = Field(description="Context URL")
    contexturlname: Optional[StrictStr] = Field(description="Context URL link name")
    customdata: Optional[StrictStr] = Field(default=None, description="Custom data to be passed to the message processor.                                 The data here is serialised using json_encode().")
    eventtype: Optional[StrictStr] = Field(default=None, description="The type of notification")
    fullmessage: Optional[StrictStr] = Field(description="The message")
    fullmessageformat: Optional[StrictInt] = Field(description="fullmessage format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    fullmessagehtml: Optional[StrictStr] = Field(description="The message in html")
    iconurl: Optional[StrictStr] = Field(default=None, description="URL for icon, only for notifications.")
    id: Optional[StrictInt] = Field(description="Message id")
    notification: Optional[StrictInt] = Field(description="Is a notification?")
    smallmessage: Optional[StrictStr] = Field(description="The shorten message")
    subject: Optional[StrictStr] = Field(description="The message subject")
    text: Optional[StrictStr] = Field(description="The message text formated")
    timecreated: Optional[StrictInt] = Field(description="Time created")
    timeread: Optional[StrictInt] = Field(description="Time read")
    userfromfullname: Optional[StrictStr] = Field(description="User from full name")
    useridfrom: Optional[StrictInt] = Field(description="User from id")
    useridto: Optional[StrictInt] = Field(description="User to id")
    usertofullname: Optional[StrictStr] = Field(description="User to full name")
    __properties: ClassVar[List[str]] = ["component", "contexturl", "contexturlname", "customdata", "eventtype", "fullmessage", "fullmessageformat", "fullmessagehtml", "iconurl", "id", "notification", "smallmessage", "subject", "text", "timecreated", "timeread", "userfromfullname", "useridfrom", "useridto", "usertofullname"]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "component": obj.get("component"),
            "contexturl": obj.get("contexturl"),
            "contexturlname": obj.get("contexturlname"),
            "customdata": obj.get("customdata"),
            "eventtype": obj.get("eventtype"),
            "fullmessage": obj.get("fullmessage"),
            "fullmessageformat": obj.get("fullmessageformat"),
            "fullmessagehtml": obj.get("fullmessagehtml"),
            "iconurl": obj.get("iconurl"),
            "id": obj.get("id"),
            "notification": obj.get("notification"),
            "smallmessage": obj.get("smallmessage"),
            "subject": obj.get("subject"),
            "text": obj.get("text"),
            "timecreated": obj.get("timecreated"),
            "timeread": obj.get("timeread"),
            "userfromfullname": obj.get("userfromfullname"),
            "useridfrom": obj.get("useridfrom"),
            "useridto": obj.get("useridto"),
            "usertofullname": obj.get("usertofullname")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


