# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.core_badges_get_badge_response_badge_alignment_inner import CoreBadgesGetBadgeResponseBadgeAlignmentInner
from poodle_async_full.models.core_badges_get_user_badge_by_hash_response_badge_inner_endorsement import CoreBadgesGetUserBadgeByHashResponseBadgeInnerEndorsement
from poodle_async_full.models.core_badges_get_user_badge_by_hash_response_badge_inner_relatedbadges_inner import CoreBadgesGetUserBadgeByHashResponseBadgeInnerRelatedbadgesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreBadgesGetUserBadgeByHashResponseBadgeInner(BaseModel):
    """
    CoreBadgesGetUserBadgeByHashResponseBadgeInner
    """ # noqa: E501
    alignment: List[CoreBadgesGetBadgeResponseBadgeAlignmentInner] = Field(description="Badge alignments")
    attachment: Optional[StrictInt] = Field(default=0, description="Attachment")
    badgeurl: StrictStr = Field(description="Badge URL")
    coursefullname: Optional[StrictStr] = Field(default='', description="Full name of the course")
    courseid: Optional[StrictInt] = Field(default=None, description="Course id")
    dateexpire: Optional[StrictInt] = Field(description="Date expire")
    dateissued: StrictInt = Field(description="Date issued")
    description: Optional[StrictStr] = Field(description="Badge description")
    email: Optional[StrictStr] = Field(default='', description="User email")
    endorsement: Optional[CoreBadgesGetUserBadgeByHashResponseBadgeInnerEndorsement] = None
    expiredate: Optional[StrictInt] = Field(default=None, description="Expire date")
    expireperiod: Optional[StrictInt] = Field(default=None, description="Expire period")
    id: Optional[StrictInt] = Field(default=0, description="Badge id")
    imagecaption: Optional[StrictStr] = Field(default=None, description="Caption of the image")
    issuedid: Optional[StrictInt] = Field(default=0, description="Issued id")
    issuercontact: Optional[StrictStr] = Field(description="Issuer contact")
    issuername: StrictStr = Field(description="Issuer name")
    issuerurl: StrictStr = Field(description="Issuer URL")
    language: Optional[StrictStr] = Field(default=None, description="Language")
    message: Optional[StrictStr] = Field(default='', description="Message")
    messagesubject: Optional[StrictStr] = Field(default='', description="Message subject")
    name: StrictStr = Field(description="Badge name")
    nextcron: Optional[StrictInt] = Field(default=None, description="Next cron")
    notification: Optional[StrictInt] = Field(default=0, description="Whether to notify when badge is awarded")
    recipientfullname: StrictStr = Field(description="Full name of the awarded user")
    recipientid: StrictInt = Field(description="Id of the awarded user")
    relatedbadges: List[CoreBadgesGetUserBadgeByHashResponseBadgeInnerRelatedbadgesInner] = Field(description="Related badges")
    status: Optional[StrictInt] = Field(default=0, description="Status")
    timecreated: Optional[StrictInt] = Field(default=0, description="Time created")
    timemodified: Optional[StrictInt] = Field(default=0, description="Time modified")
    type: Optional[StrictInt] = Field(default=0, description="Type")
    uniquehash: StrictStr = Field(description="Unique hash")
    usercreated: Optional[StrictInt] = Field(default=0, description="User created")
    usermodified: Optional[StrictInt] = Field(default=0, description="User modified")
    version: Optional[StrictStr] = Field(default=None, description="Version")
    visible: Optional[StrictInt] = Field(default=0, description="Visible")
    __properties: ClassVar[List[str]] = ["alignment", "attachment", "badgeurl", "coursefullname", "courseid", "dateexpire", "dateissued", "description", "email", "endorsement", "expiredate", "expireperiod", "id", "imagecaption", "issuedid", "issuercontact", "issuername", "issuerurl", "language", "message", "messagesubject", "name", "nextcron", "notification", "recipientfullname", "recipientid", "relatedbadges", "status", "timecreated", "timemodified", "type", "uniquehash", "usercreated", "usermodified", "version", "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 CoreBadgesGetUserBadgeByHashResponseBadgeInner 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 alignment (list)
        _items = []
        if self.alignment:
            for _item_alignment in self.alignment:
                if _item_alignment:
                    _items.append(_item_alignment.to_dict())
            _dict['alignment'] = _items
        # override the default output from pydantic by calling `to_dict()` of endorsement
        if self.endorsement:
            _dict['endorsement'] = self.endorsement.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in relatedbadges (list)
        _items = []
        if self.relatedbadges:
            for _item_relatedbadges in self.relatedbadges:
                if _item_relatedbadges:
                    _items.append(_item_relatedbadges.to_dict())
            _dict['relatedbadges'] = _items
        # set to None if courseid (nullable) is None
        # and model_fields_set contains the field
        if self.courseid is None and "courseid" in self.model_fields_set:
            _dict['courseid'] = None

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "alignment": [CoreBadgesGetBadgeResponseBadgeAlignmentInner.from_dict(_item) for _item in obj["alignment"]] if obj.get("alignment") is not None else None,
            "attachment": obj.get("attachment") if obj.get("attachment") is not None else 0,
            "badgeurl": obj.get("badgeurl") if obj.get("badgeurl") is not None else '',
            "coursefullname": obj.get("coursefullname") if obj.get("coursefullname") is not None else '',
            "courseid": obj.get("courseid"),
            "dateexpire": obj.get("dateexpire"),
            "dateissued": obj.get("dateissued") if obj.get("dateissued") is not None else 0,
            "description": obj.get("description"),
            "email": obj.get("email") if obj.get("email") is not None else '',
            "endorsement": CoreBadgesGetUserBadgeByHashResponseBadgeInnerEndorsement.from_dict(obj["endorsement"]) if obj.get("endorsement") is not None else None,
            "expiredate": obj.get("expiredate"),
            "expireperiod": obj.get("expireperiod"),
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "imagecaption": obj.get("imagecaption"),
            "issuedid": obj.get("issuedid") if obj.get("issuedid") is not None else 0,
            "issuercontact": obj.get("issuercontact"),
            "issuername": obj.get("issuername") if obj.get("issuername") is not None else '',
            "issuerurl": obj.get("issuerurl") if obj.get("issuerurl") is not None else '',
            "language": obj.get("language"),
            "message": obj.get("message") if obj.get("message") is not None else '',
            "messagesubject": obj.get("messagesubject") if obj.get("messagesubject") is not None else '',
            "name": obj.get("name") if obj.get("name") is not None else '',
            "nextcron": obj.get("nextcron"),
            "notification": obj.get("notification") if obj.get("notification") is not None else 0,
            "recipientfullname": obj.get("recipientfullname") if obj.get("recipientfullname") is not None else '',
            "recipientid": obj.get("recipientid") if obj.get("recipientid") is not None else 0,
            "relatedbadges": [CoreBadgesGetUserBadgeByHashResponseBadgeInnerRelatedbadgesInner.from_dict(_item) for _item in obj["relatedbadges"]] if obj.get("relatedbadges") is not None else None,
            "status": obj.get("status") if obj.get("status") is not None else 0,
            "timecreated": obj.get("timecreated") if obj.get("timecreated") is not None else 0,
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0,
            "type": obj.get("type") if obj.get("type") is not None else 0,
            "uniquehash": obj.get("uniquehash") if obj.get("uniquehash") is not None else '',
            "usercreated": obj.get("usercreated") if obj.get("usercreated") is not None else 0,
            "usermodified": obj.get("usermodified") if obj.get("usermodified") is not None else 0,
            "version": obj.get("version"),
            "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


