# coding: utf-8

"""
    Moodle Webservice API

    Auto-generated OpenAPI spec for Moodle's Webservice API.

    The version of the OpenAPI document: 5.0.2 (Build: 20250811)
    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

class CoreNotesGetNotesResponseNotesInner(BaseModel):
    """
    note
    """ # noqa: E501
    courseid: Optional[StrictInt] = Field(default=None, description="course id of the note")
    format: Optional[StrictInt] = Field(default=None, description="text format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    noteid: Optional[StrictInt] = Field(default=None, description="id of the note")
    publishstate: Optional[StrictStr] = Field(default=None, description="'personal', 'course' or 'site'")
    text: Optional[StrictStr] = Field(default=None, description="the text of the message - text or HTML")
    userid: Optional[StrictInt] = Field(default=None, description="id of the user the note is about")
    __properties: ClassVar[List[str]] = ["courseid", "format", "noteid", "publishstate", "text", "userid"]

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

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

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

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

        return _dict

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

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "courseid": obj.get("courseid"),
            "format": obj.get("format"),
            "noteid": obj.get("noteid"),
            "publishstate": obj.get("publishstate"),
            "text": obj.get("text"),
            "userid": obj.get("userid")
        })
        return _obj


