# 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.core_calendar_get_calendar_day_view_response_date import CoreCalendarGetCalendarDayViewResponseDate
from poodle_async_full.models.core_calendar_get_calendar_monthly_view_response_daynames_inner import CoreCalendarGetCalendarMonthlyViewResponseDaynamesInner
from poodle_async_full.models.core_calendar_get_calendar_monthly_view_response_weeks_inner import CoreCalendarGetCalendarMonthlyViewResponseWeeksInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreCalendarGetCalendarMonthlyViewResponse(BaseModel):
    """
    CoreCalendarGetCalendarMonthlyViewResponse
    """ # noqa: E501
    calendarinstanceid: StrictInt = Field(description="calendarinstanceid")
    categoryid: Optional[StrictInt] = Field(default=0, description="categoryid")
    courseid: StrictInt = Field(description="courseid")
    var_date: CoreCalendarGetCalendarDayViewResponseDate = Field(alias="date")
    daynames: List[CoreCalendarGetCalendarMonthlyViewResponseDaynamesInner] = Field(description="daynames")
    defaulteventcontext: StrictInt = Field(description="defaulteventcontext")
    filter_selector: Optional[StrictStr] = Field(default='', description="filter_selector")
    includenavigation: StrictBool = Field(description="includenavigation")
    initialeventsloaded: StrictBool = Field(description="initialeventsloaded")
    larrow: StrictStr = Field(description="larrow")
    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")
    showviewselector: StrictBool = Field(description="showviewselector")
    url: StrictStr = Field(description="url")
    view: StrictStr = Field(description="view")
    viewinginblock: StrictBool = Field(description="viewinginblock")
    viewingmonth: StrictBool = Field(description="viewingmonth")
    weeks: List[CoreCalendarGetCalendarMonthlyViewResponseWeeksInner] = Field(description="weeks")
    __properties: ClassVar[List[str]] = ["calendarinstanceid", "categoryid", "courseid", "date", "daynames", "defaulteventcontext", "filter_selector", "includenavigation", "initialeventsloaded", "larrow", "nextperiod", "nextperiodlink", "nextperiodname", "periodname", "previousperiod", "previousperiodlink", "previousperiodname", "rarrow", "showviewselector", "url", "view", "viewinginblock", "viewingmonth", "weeks"]

    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 CoreCalendarGetCalendarMonthlyViewResponse 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 daynames (list)
        _items = []
        if self.daynames:
            for _item_daynames in self.daynames:
                if _item_daynames:
                    _items.append(_item_daynames.to_dict())
            _dict['daynames'] = _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()
        # override the default output from pydantic by calling `to_dict()` of each item in weeks (list)
        _items = []
        if self.weeks:
            for _item_weeks in self.weeks:
                if _item_weeks:
                    _items.append(_item_weeks.to_dict())
            _dict['weeks'] = _items
        return _dict

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

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

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

        data = {
            "calendarinstanceid": obj.get("calendarinstanceid") if obj.get("calendarinstanceid") is not None else 0,
            "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,
            "daynames": [CoreCalendarGetCalendarMonthlyViewResponseDaynamesInner.from_dict(_item) for _item in obj["daynames"]] if obj.get("daynames") is not None else None,
            "defaulteventcontext": obj.get("defaulteventcontext") if obj.get("defaulteventcontext") is not None else 0,
            "filter_selector": obj.get("filter_selector") if obj.get("filter_selector") is not None else '',
            "includenavigation": obj.get("includenavigation") if obj.get("includenavigation") is not None else True,
            "initialeventsloaded": obj.get("initialeventsloaded") if obj.get("initialeventsloaded") is not None else True,
            "larrow": obj.get("larrow") if obj.get("larrow") is not None else '',
            "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 '',
            "showviewselector": obj.get("showviewselector") if obj.get("showviewselector") is not None else True,
            "url": obj.get("url") if obj.get("url") is not None else '',
            "view": obj.get("view") if obj.get("view") is not None else '',
            "viewinginblock": obj.get("viewinginblock") if obj.get("viewinginblock") is not None else False,
            "viewingmonth": obj.get("viewingmonth") if obj.get("viewingmonth") is not None else True,
            "weeks": [CoreCalendarGetCalendarMonthlyViewResponseWeeksInner.from_dict(_item) for _item in obj["weeks"]] if obj.get("weeks") is not None else None
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


