# 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 typing import Optional, Set
from typing_extensions import Self

class CoreFilesGetFilesResponseFilesInner(BaseModel):
    """
    CoreFilesGetFilesResponseFilesInner
    """ # noqa: E501
    author: Optional[StrictStr] = Field(default=None, description="File owner")
    component: Optional[StrictStr]
    contextid: Optional[StrictInt]
    filearea: Optional[StrictStr]
    filename: Optional[StrictStr]
    filepath: Optional[StrictStr]
    filesize: Optional[StrictInt] = Field(default=None, description="File size")
    isdir: Optional[StrictBool]
    itemid: Optional[StrictInt]
    license: Optional[StrictStr] = Field(default=None, description="File license")
    timecreated: Optional[StrictInt] = Field(default=None, description="Time created")
    timemodified: Optional[StrictInt]
    url: Optional[StrictStr]
    __properties: ClassVar[List[str]] = ["author", "component", "contextid", "filearea", "filename", "filepath", "filesize", "isdir", "itemid", "license", "timecreated", "timemodified", "url"]

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "author": obj.get("author"),
            "component": obj.get("component"),
            "contextid": obj.get("contextid"),
            "filearea": obj.get("filearea"),
            "filename": obj.get("filename"),
            "filepath": obj.get("filepath"),
            "filesize": obj.get("filesize"),
            "isdir": obj.get("isdir"),
            "itemid": obj.get("itemid"),
            "license": obj.get("license"),
            "timecreated": obj.get("timecreated"),
            "timemodified": obj.get("timemodified"),
            "url": obj.get("url")
        })
        return _obj


