# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.core_course_get_contents_response_inner_modules_inner_activitybadge_one_of_badgeextraattributes_inner import CoreCourseGetContentsResponseInnerModulesInnerActivitybadgeOneOfBadgeextraattributesInner
from typing import Optional, Set
from typing_extensions import Self

class CoreCourseGetContentsResponseInnerModulesInnerActivitybadgeOneOf(BaseModel):
    """
    Activity badge to display near the name
    """ # noqa: E501
    badgecontent: Optional[StrictStr] = Field(default=None, description="The content to be displayed in the activity badge")
    badgeelementid: Optional[StrictStr] = Field(default=None, description="An optional id in case the module wants to add some code for the activity badge")
    badgeextraattributes: Optional[List[CoreCourseGetContentsResponseInnerModulesInnerActivitybadgeOneOfBadgeextraattributesInner]] = Field(default=None, description="An optional array of extra HTML attributes to add to the badge element")
    badgestyle: Optional[StrictStr] = Field(default=None, description="The style for the activity badge")
    badgeurl: Optional[StrictStr] = Field(default=None, description="An optional URL to redirect the user when the activity badge is clicked")
    __properties: ClassVar[List[str]] = ["badgecontent", "badgeelementid", "badgeextraattributes", "badgestyle", "badgeurl"]

    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 CoreCourseGetContentsResponseInnerModulesInnerActivitybadgeOneOf 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 each item in badgeextraattributes (list)
        _items = []
        if self.badgeextraattributes:
            for _item_badgeextraattributes in self.badgeextraattributes:
                if _item_badgeextraattributes:
                    _items.append(_item_badgeextraattributes.to_dict())
            _dict['badgeextraattributes'] = _items
        # set to None if badgecontent (nullable) is None
        # and model_fields_set contains the field
        if self.badgecontent is None and "badgecontent" in self.model_fields_set:
            _dict['badgecontent'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "badgecontent": obj.get("badgecontent"),
            "badgeelementid": obj.get("badgeelementid"),
            "badgeextraattributes": [CoreCourseGetContentsResponseInnerModulesInnerActivitybadgeOneOfBadgeextraattributesInner.from_dict(_item) for _item in obj["badgeextraattributes"]] if obj.get("badgeextraattributes") is not None else None,
            "badgestyle": obj.get("badgestyle"),
            "badgeurl": obj.get("badgeurl")
        })
        return _obj


