# 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 CoreCourseGetCategoriesResponseInner(BaseModel):
    """
    List of categories
    """ # noqa: E501
    coursecount: Optional[StrictInt] = Field(description="number of courses in this category")
    depth: Optional[StrictInt] = Field(description="category depth")
    description: Optional[StrictStr] = Field(description="category description")
    descriptionformat: Optional[StrictInt] = Field(description="description format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    id: Optional[StrictInt] = Field(description="category id")
    idnumber: Optional[StrictStr] = Field(default=None, description="category id number")
    name: Optional[StrictStr] = Field(description="category name")
    parent: Optional[StrictInt] = Field(description="parent category id")
    path: Optional[StrictStr] = Field(description="category path")
    sortorder: Optional[StrictInt] = Field(description="category sorting order")
    theme: Optional[StrictStr] = Field(default=None, description="category theme")
    timemodified: Optional[StrictInt] = Field(default=None, description="timestamp")
    visible: Optional[StrictInt] = Field(default=None, description="1: available, 0:not available")
    visibleold: Optional[StrictInt] = Field(default=None, description="1: available, 0:not available")
    __properties: ClassVar[List[str]] = ["coursecount", "depth", "description", "descriptionformat", "id", "idnumber", "name", "parent", "path", "sortorder", "theme", "timemodified", "visible", "visibleold"]

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "coursecount": obj.get("coursecount"),
            "depth": obj.get("depth"),
            "description": obj.get("description"),
            "descriptionformat": obj.get("descriptionformat"),
            "id": obj.get("id"),
            "idnumber": obj.get("idnumber"),
            "name": obj.get("name"),
            "parent": obj.get("parent"),
            "path": obj.get("path"),
            "sortorder": obj.get("sortorder"),
            "theme": obj.get("theme"),
            "timemodified": obj.get("timemodified"),
            "visible": obj.get("visible"),
            "visibleold": obj.get("visibleold")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


