# coding: utf-8

"""
    Moodle Webservice API

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

    The version of the OpenAPI document: 4.5 (Build: 20241007)
    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 poodle_async_full.models.core_calendar_get_calendar_day_view_response_date import CoreCalendarGetCalendarDayViewResponseDate
from poodle_async_full.models.core_calendar_get_calendar_day_view_response_events_inner import CoreCalendarGetCalendarDayViewResponseEventsInner
from typing import Optional, Set
from typing_extensions import Self

class CoreCalendarGetCalendarDayViewResponse(BaseModel):
    """
    CoreCalendarGetCalendarDayViewResponse
    """ # noqa: E501
    categoryid: Optional[StrictInt] = Field(default=0, description="categoryid")
    courseid: StrictInt = Field(description="courseid")
    var_date: CoreCalendarGetCalendarDayViewResponseDate = Field(alias="date")
    defaulteventcontext: StrictInt = Field(description="defaulteventcontext")
    events: List[CoreCalendarGetCalendarDayViewResponseEventsInner] = Field(description="events")
    filter_selector: StrictStr = Field(description="filter_selector")
    larrow: StrictStr = Field(description="larrow")
    neweventtimestamp: StrictInt = Field(description="neweventtimestamp")
    nextperiod: CoreCalendarGetCalendarDayViewResponseDate
    nextperiodlink: StrictStr = Field(description="nextperiodlink")
    nextperiodname: StrictStr = Field(description="nextperiodname")
    periodname: StrictStr = Field(description="periodname")
    previousperiod: CoreCalendarGetCalendarDayViewResponseDate
    previousperiodlink: StrictStr = Field(description="previousperiodlink")
    previousperiodname: StrictStr = Field(description="previousperiodname")
    rarrow: StrictStr = Field(description="rarrow")
    __properties: ClassVar[List[str]] = ["categoryid", "courseid", "date", "defaulteventcontext", "events", "filter_selector", "larrow", "neweventtimestamp", "nextperiod", "nextperiodlink", "nextperiodname", "periodname", "previousperiod", "previousperiodlink", "previousperiodname", "rarrow"]

    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 CoreCalendarGetCalendarDayViewResponse 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 var_date
        if self.var_date:
            _dict['date'] = self.var_date.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in events (list)
        _items = []
        if self.events:
            for _item_events in self.events:
                if _item_events:
                    _items.append(_item_events.to_dict())
            _dict['events'] = _items
        # override the default output from pydantic by calling `to_dict()` of nextperiod
        if self.nextperiod:
            _dict['nextperiod'] = self.nextperiod.to_dict()
        # override the default output from pydantic by calling `to_dict()` of previousperiod
        if self.previousperiod:
            _dict['previousperiod'] = self.previousperiod.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "categoryid": obj.get("categoryid") if obj.get("categoryid") is not None else 0,
            "courseid": obj.get("courseid") if obj.get("courseid") is not None else 0,
            "date": CoreCalendarGetCalendarDayViewResponseDate.from_dict(obj["date"]) if obj.get("date") is not None else None,
            "defaulteventcontext": obj.get("defaulteventcontext") if obj.get("defaulteventcontext") is not None else 0,
            "events": [CoreCalendarGetCalendarDayViewResponseEventsInner.from_dict(_item) for _item in obj["events"]] if obj.get("events") is not None else None,
            "filter_selector": obj.get("filter_selector") if obj.get("filter_selector") is not None else '',
            "larrow": obj.get("larrow") if obj.get("larrow") is not None else '',
            "neweventtimestamp": obj.get("neweventtimestamp") if obj.get("neweventtimestamp") is not None else 0,
            "nextperiod": CoreCalendarGetCalendarDayViewResponseDate.from_dict(obj["nextperiod"]) if obj.get("nextperiod") is not None else None,
            "nextperiodlink": obj.get("nextperiodlink") if obj.get("nextperiodlink") is not None else '',
            "nextperiodname": obj.get("nextperiodname") if obj.get("nextperiodname") is not None else '',
            "periodname": obj.get("periodname") if obj.get("periodname") is not None else '',
            "previousperiod": CoreCalendarGetCalendarDayViewResponseDate.from_dict(obj["previousperiod"]) if obj.get("previousperiod") is not None else None,
            "previousperiodlink": obj.get("previousperiodlink") if obj.get("previousperiodlink") is not None else '',
            "previousperiodname": obj.get("previousperiodname") if obj.get("previousperiodname") is not None else '',
            "rarrow": obj.get("rarrow") if obj.get("rarrow") is not None else ''
        })
        return _obj


