# 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 CoreCalendarCreateCalendarEventsResponseEventsInner(BaseModel):
    """
    event
    """ # noqa: E501
    courseid: Optional[StrictInt] = Field(description="course id")
    description: Optional[StrictStr] = Field(default=None, description="Description")
    eventtype: Optional[StrictStr] = Field(description="Event type")
    format: Optional[StrictInt] = Field(description="description format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    groupid: Optional[StrictInt] = Field(description="group id")
    id: Optional[StrictInt] = Field(description="event id")
    instance: Optional[StrictInt] = Field(description="instance id")
    modulename: Optional[StrictStr] = Field(default=None, description="module name")
    name: Optional[StrictStr] = Field(description="event name")
    repeatid: Optional[StrictInt] = Field(default=None, description="repeat id")
    sequence: Optional[StrictInt] = Field(description="sequence")
    subscriptionid: Optional[StrictInt] = Field(default=None, description="Subscription id")
    timeduration: Optional[StrictInt] = Field(description="time duration")
    timemodified: Optional[StrictInt] = Field(description="time modified")
    timestart: Optional[StrictInt] = Field(description="timestart")
    userid: Optional[StrictInt] = Field(description="user id")
    uuid: Optional[StrictStr] = Field(default='', description="unique id of ical events")
    visible: Optional[StrictInt] = Field(description="visible")
    __properties: ClassVar[List[str]] = ["courseid", "description", "eventtype", "format", "groupid", "id", "instance", "modulename", "name", "repeatid", "sequence", "subscriptionid", "timeduration", "timemodified", "timestart", "userid", "uuid", "visible"]

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "courseid": obj.get("courseid"),
            "description": obj.get("description"),
            "eventtype": obj.get("eventtype"),
            "format": obj.get("format"),
            "groupid": obj.get("groupid"),
            "id": obj.get("id"),
            "instance": obj.get("instance"),
            "modulename": obj.get("modulename"),
            "name": obj.get("name"),
            "repeatid": obj.get("repeatid"),
            "sequence": obj.get("sequence"),
            "subscriptionid": obj.get("subscriptionid"),
            "timeduration": obj.get("timeduration"),
            "timemodified": obj.get("timemodified"),
            "timestart": obj.get("timestart"),
            "userid": obj.get("userid"),
            "uuid": obj.get("uuid") if obj.get("uuid") is not None else '',
            "visible": obj.get("visible")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


