# coding: utf-8

"""
    Moodle Webservice API

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

    The version of the OpenAPI document: 5.0.2 (Build: 20250811)
    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 typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ToolMobileGetPluginsSupportingMobileResponsePluginsInner(BaseModel):
    """
    ToolMobileGetPluginsSupportingMobileResponsePluginsInner
    """ # noqa: E501
    addon: Optional[StrictStr] = Field(description="The Mobile addon (package) name.")
    component: Optional[StrictStr] = Field(description="The plugin component name.")
    dependencies: List[Optional[StrictStr]] = Field(description="The list of Mobile addons this addon depends on.")
    filehash: Optional[StrictStr] = Field(description="The addon package hash or empty if it doesn't exist.")
    filesize: Optional[StrictInt] = Field(description="The addon package size or empty if it doesn't exist.")
    fileurl: Optional[StrictStr] = Field(description="The addon package url for download                                                             or empty if it doesn't exist.")
    handlers: Optional[StrictStr] = Field(default=None, description="Handlers definition (JSON)")
    lang: Optional[StrictStr] = Field(default=None, description="Language strings used by the handlers (JSON)")
    version: Optional[StrictStr] = Field(description="The plugin version number.")
    __properties: ClassVar[List[str]] = ["addon", "component", "dependencies", "filehash", "filesize", "fileurl", "handlers", "lang", "version"]

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

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

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

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

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

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

        # set to None if lang (nullable) is None
        # and model_fields_set contains the field
        if self.lang is None and "lang" in self.model_fields_set:
            _dict['lang'] = 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 ToolMobileGetPluginsSupportingMobileResponsePluginsInner from a dict"""
        if obj is None:
            return None

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

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

        data = {
            "addon": obj.get("addon"),
            "component": obj.get("component"),
            "dependencies": obj.get("dependencies"),
            "filehash": obj.get("filehash"),
            "filesize": obj.get("filesize"),
            "fileurl": obj.get("fileurl"),
            "handlers": obj.get("handlers"),
            "lang": obj.get("lang"),
            "version": obj.get("version")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


