# 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.block_starredcourses_get_starred_courses_response_inner import BlockStarredcoursesGetStarredCoursesResponseInner
from poodle_async_full.models.core_calendar_get_action_events_by_course_response_events_inner_action import CoreCalendarGetActionEventsByCourseResponseEventsInnerAction
from poodle_async_full.models.core_calendar_get_action_events_by_course_response_events_inner_category import CoreCalendarGetActionEventsByCourseResponseEventsInnerCategory
from poodle_async_full.models.core_calendar_get_action_events_by_course_response_events_inner_icon import CoreCalendarGetActionEventsByCourseResponseEventsInnerIcon
from poodle_async_full.models.core_calendar_get_action_events_by_course_response_events_inner_subscription import CoreCalendarGetActionEventsByCourseResponseEventsInnerSubscription
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreCalendarGetActionEventsByCourseResponseEventsInner(BaseModel):
    """
    CoreCalendarGetActionEventsByCourseResponseEventsInner
    """ # noqa: E501
    action: Optional[CoreCalendarGetActionEventsByCourseResponseEventsInnerAction] = None
    activityname: Optional[StrictStr] = Field(default=None, description="activityname")
    activitystr: Optional[StrictStr] = Field(default=None, description="activitystr")
    branded: Optional[StrictBool] = Field(default=False, description="branded")
    candelete: StrictBool = Field(description="candelete")
    canedit: StrictBool = Field(description="canedit")
    category: Optional[CoreCalendarGetActionEventsByCourseResponseEventsInnerCategory] = None
    categoryid: Optional[StrictInt] = Field(default=None, description="categoryid")
    component: Optional[StrictStr] = Field(default=None, description="component")
    course: Optional[BlockStarredcoursesGetStarredCoursesResponseInner] = None
    deleteurl: StrictStr = Field(description="deleteurl")
    description: Optional[StrictStr] = Field(default=None, description="description")
    descriptionformat: Optional[StrictInt] = Field(default=1, description="description format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    editurl: StrictStr = Field(description="editurl")
    eventcount: Optional[StrictInt] = Field(default=None, description="eventcount")
    eventtype: StrictStr = Field(description="eventtype")
    formattedlocation: StrictStr = Field(description="formattedlocation")
    formattedtime: StrictStr = Field(description="formattedtime")
    groupid: Optional[StrictInt] = Field(default=None, description="groupid")
    groupname: Optional[StrictStr] = Field(default=None, description="groupname")
    icon: CoreCalendarGetActionEventsByCourseResponseEventsInnerIcon
    id: StrictInt = Field(description="id")
    instance: Optional[StrictInt] = Field(default=None, description="instance")
    isactionevent: StrictBool = Field(description="isactionevent")
    iscategoryevent: StrictBool = Field(description="iscategoryevent")
    iscourseevent: StrictBool = Field(description="iscourseevent")
    location: Optional[StrictStr] = Field(default=None, description="location")
    modulename: Optional[StrictStr] = Field(default=None, description="modulename")
    name: StrictStr = Field(description="name")
    normalisedeventtype: StrictStr = Field(description="normalisedeventtype")
    normalisedeventtypetext: StrictStr = Field(description="normalisedeventtypetext")
    overdue: Optional[StrictBool] = Field(default=False, description="overdue")
    purpose: StrictStr = Field(description="purpose")
    repeatid: Optional[StrictInt] = Field(default=None, description="repeatid")
    subscription: Optional[CoreCalendarGetActionEventsByCourseResponseEventsInnerSubscription] = None
    timeduration: StrictInt = Field(description="timeduration")
    timemodified: StrictInt = Field(description="timemodified")
    timesort: StrictInt = Field(description="timesort")
    timestart: StrictInt = Field(description="timestart")
    timeusermidnight: StrictInt = Field(description="timeusermidnight")
    url: StrictStr = Field(description="url")
    userid: Optional[StrictInt] = Field(default=None, description="userid")
    viewurl: StrictStr = Field(description="viewurl")
    visible: StrictInt = Field(description="visible")
    __properties: ClassVar[List[str]] = ["action", "activityname", "activitystr", "branded", "candelete", "canedit", "category", "categoryid", "component", "course", "deleteurl", "description", "descriptionformat", "editurl", "eventcount", "eventtype", "formattedlocation", "formattedtime", "groupid", "groupname", "icon", "id", "instance", "isactionevent", "iscategoryevent", "iscourseevent", "location", "modulename", "name", "normalisedeventtype", "normalisedeventtypetext", "overdue", "purpose", "repeatid", "subscription", "timeduration", "timemodified", "timesort", "timestart", "timeusermidnight", "url", "userid", "viewurl", "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 CoreCalendarGetActionEventsByCourseResponseEventsInner 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 action
        if self.action:
            _dict['action'] = self.action.to_dict()
        # override the default output from pydantic by calling `to_dict()` of category
        if self.category:
            _dict['category'] = self.category.to_dict()
        # override the default output from pydantic by calling `to_dict()` of course
        if self.course:
            _dict['course'] = self.course.to_dict()
        # override the default output from pydantic by calling `to_dict()` of icon
        if self.icon:
            _dict['icon'] = self.icon.to_dict()
        # override the default output from pydantic by calling `to_dict()` of subscription
        if self.subscription:
            _dict['subscription'] = self.subscription.to_dict()
        # set to None if activityname (nullable) is None
        # and model_fields_set contains the field
        if self.activityname is None and "activityname" in self.model_fields_set:
            _dict['activityname'] = None

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

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

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

        # set to None if eventcount (nullable) is None
        # and model_fields_set contains the field
        if self.eventcount is None and "eventcount" in self.model_fields_set:
            _dict['eventcount'] = 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 groupname (nullable) is None
        # and model_fields_set contains the field
        if self.groupname is None and "groupname" in self.model_fields_set:
            _dict['groupname'] = 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 location (nullable) is None
        # and model_fields_set contains the field
        if self.location is None and "location" in self.model_fields_set:
            _dict['location'] = 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 overdue (nullable) is None
        # and model_fields_set contains the field
        if self.overdue is None and "overdue" in self.model_fields_set:
            _dict['overdue'] = 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 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 CoreCalendarGetActionEventsByCourseResponseEventsInner from a dict"""
        if obj is None:
            return None

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

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

        data = {
            "action": CoreCalendarGetActionEventsByCourseResponseEventsInnerAction.from_dict(obj["action"]) if obj.get("action") is not None else None,
            "activityname": obj.get("activityname"),
            "activitystr": obj.get("activitystr"),
            "branded": obj.get("branded") if obj.get("branded") is not None else False,
            "candelete": obj.get("candelete") if obj.get("candelete") is not None else False,
            "canedit": obj.get("canedit") if obj.get("canedit") is not None else False,
            "category": CoreCalendarGetActionEventsByCourseResponseEventsInnerCategory.from_dict(obj["category"]) if obj.get("category") is not None else None,
            "categoryid": obj.get("categoryid"),
            "component": obj.get("component"),
            "course": BlockStarredcoursesGetStarredCoursesResponseInner.from_dict(obj["course"]) if obj.get("course") is not None else None,
            "deleteurl": obj.get("deleteurl") if obj.get("deleteurl") is not None else '',
            "description": obj.get("description"),
            "descriptionformat": obj.get("descriptionformat") if obj.get("descriptionformat") is not None else 1,
            "editurl": obj.get("editurl") if obj.get("editurl") is not None else '',
            "eventcount": obj.get("eventcount"),
            "eventtype": obj.get("eventtype") if obj.get("eventtype") is not None else '',
            "formattedlocation": obj.get("formattedlocation") if obj.get("formattedlocation") is not None else '',
            "formattedtime": obj.get("formattedtime") if obj.get("formattedtime") is not None else '',
            "groupid": obj.get("groupid"),
            "groupname": obj.get("groupname"),
            "icon": CoreCalendarGetActionEventsByCourseResponseEventsInnerIcon.from_dict(obj["icon"]) if obj.get("icon") is not None else None,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "instance": obj.get("instance"),
            "isactionevent": obj.get("isactionevent") if obj.get("isactionevent") is not None else False,
            "iscategoryevent": obj.get("iscategoryevent") if obj.get("iscategoryevent") is not None else False,
            "iscourseevent": obj.get("iscourseevent") if obj.get("iscourseevent") is not None else False,
            "location": obj.get("location"),
            "modulename": obj.get("modulename"),
            "name": obj.get("name") if obj.get("name") is not None else '',
            "normalisedeventtype": obj.get("normalisedeventtype") if obj.get("normalisedeventtype") is not None else '',
            "normalisedeventtypetext": obj.get("normalisedeventtypetext") if obj.get("normalisedeventtypetext") is not None else '',
            "overdue": obj.get("overdue") if obj.get("overdue") is not None else False,
            "purpose": obj.get("purpose") if obj.get("purpose") is not None else '',
            "repeatid": obj.get("repeatid"),
            "subscription": CoreCalendarGetActionEventsByCourseResponseEventsInnerSubscription.from_dict(obj["subscription"]) if obj.get("subscription") is not None else None,
            "timeduration": obj.get("timeduration") if obj.get("timeduration") is not None else 0,
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0,
            "timesort": obj.get("timesort") if obj.get("timesort") is not None else 0,
            "timestart": obj.get("timestart") if obj.get("timestart") is not None else 0,
            "timeusermidnight": obj.get("timeusermidnight") if obj.get("timeusermidnight") is not None else 0,
            "url": obj.get("url") if obj.get("url") is not None else '',
            "userid": obj.get("userid"),
            "viewurl": obj.get("viewurl") if obj.get("viewurl") is not None else '',
            "visible": obj.get("visible") if obj.get("visible") is not None else 0
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


