# 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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.mod_forum_set_pin_state_response_capabilities import ModForumSetPinStateResponseCapabilities
from poodle_async_full.models.mod_forum_set_pin_state_response_group import ModForumSetPinStateResponseGroup
from poodle_async_full.models.mod_forum_set_pin_state_response_timed import ModForumSetPinStateResponseTimed
from poodle_async_full.models.mod_forum_set_pin_state_response_times import ModForumSetPinStateResponseTimes
from poodle_async_full.models.mod_forum_set_pin_state_response_urls import ModForumSetPinStateResponseUrls
from poodle_async_full.models.mod_forum_set_pin_state_response_userstate import ModForumSetPinStateResponseUserstate
from typing import Optional, Set
from typing_extensions import Self

class ModForumSetPinStateResponse(BaseModel):
    """
    ModForumSetPinStateResponse
    """ # noqa: E501
    capabilities: ModForumSetPinStateResponseCapabilities
    firstpostid: StrictInt = Field(description="firstpostid")
    forumid: StrictInt = Field(description="forumid")
    group: Optional[ModForumSetPinStateResponseGroup] = None
    id: StrictInt = Field(description="id")
    istimelocked: StrictBool = Field(description="istimelocked")
    locked: StrictBool = Field(description="locked")
    name: StrictStr = Field(description="name")
    pinned: StrictBool = Field(description="pinned")
    timed: ModForumSetPinStateResponseTimed
    times: ModForumSetPinStateResponseTimes
    urls: ModForumSetPinStateResponseUrls
    userstate: ModForumSetPinStateResponseUserstate
    __properties: ClassVar[List[str]] = ["capabilities", "firstpostid", "forumid", "group", "id", "istimelocked", "locked", "name", "pinned", "timed", "times", "urls", "userstate"]

    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 ModForumSetPinStateResponse 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 capabilities
        if self.capabilities:
            _dict['capabilities'] = self.capabilities.to_dict()
        # override the default output from pydantic by calling `to_dict()` of group
        if self.group:
            _dict['group'] = self.group.to_dict()
        # override the default output from pydantic by calling `to_dict()` of timed
        if self.timed:
            _dict['timed'] = self.timed.to_dict()
        # override the default output from pydantic by calling `to_dict()` of times
        if self.times:
            _dict['times'] = self.times.to_dict()
        # override the default output from pydantic by calling `to_dict()` of urls
        if self.urls:
            _dict['urls'] = self.urls.to_dict()
        # override the default output from pydantic by calling `to_dict()` of userstate
        if self.userstate:
            _dict['userstate'] = self.userstate.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "capabilities": ModForumSetPinStateResponseCapabilities.from_dict(obj["capabilities"]) if obj.get("capabilities") is not None else None,
            "firstpostid": obj.get("firstpostid") if obj.get("firstpostid") is not None else 0,
            "forumid": obj.get("forumid") if obj.get("forumid") is not None else 0,
            "group": ModForumSetPinStateResponseGroup.from_dict(obj["group"]) if obj.get("group") is not None else None,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "istimelocked": obj.get("istimelocked") if obj.get("istimelocked") is not None else False,
            "locked": obj.get("locked") if obj.get("locked") is not None else False,
            "name": obj.get("name") if obj.get("name") is not None else '',
            "pinned": obj.get("pinned") if obj.get("pinned") is not None else False,
            "timed": ModForumSetPinStateResponseTimed.from_dict(obj["timed"]) if obj.get("timed") is not None else None,
            "times": ModForumSetPinStateResponseTimes.from_dict(obj["times"]) if obj.get("times") is not None else None,
            "urls": ModForumSetPinStateResponseUrls.from_dict(obj["urls"]) if obj.get("urls") is not None else None,
            "userstate": ModForumSetPinStateResponseUserstate.from_dict(obj["userstate"]) if obj.get("userstate") is not None else None
        })
        return _obj


