# 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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.core_block_get_course_blocks_response_blocks_inner_contents_files_inner import CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner
from poodle_async_full.models.core_cohort_get_cohorts_response_inner_customfields_inner import CoreCohortGetCohortsResponseInnerCustomfieldsInner
from poodle_async_full.models.core_course_get_courses_by_field_response_courses_inner_contacts_inner import CoreCourseGetCoursesByFieldResponseCoursesInnerContactsInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreCourseSearchCoursesResponseCoursesInner(BaseModel):
    """
    CoreCourseSearchCoursesResponseCoursesInner
    """ # noqa: E501
    categoryid: Optional[StrictInt] = Field(description="category id")
    categoryname: Optional[StrictStr] = Field(description="category name")
    contacts: List[CoreCourseGetCoursesByFieldResponseCoursesInnerContactsInner] = Field(description="contact users")
    courseimage: Optional[StrictStr] = Field(default=None, description="Course image")
    customfields: Optional[List[CoreCohortGetCohortsResponseInnerCustomfieldsInner]] = Field(default=None, description="Custom fields")
    displayname: Optional[StrictStr] = Field(description="course display name")
    enrollmentmethods: List[Optional[StrictStr]] = Field(description="enrollment methods list")
    fullname: Optional[StrictStr] = Field(description="course full name")
    id: Optional[StrictInt] = Field(description="course id")
    overviewfiles: List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner] = Field(description="additional overview files attached to this course")
    shortname: Optional[StrictStr] = Field(description="course short name")
    showactivitydates: Optional[StrictBool] = Field(description="Whether the activity dates are shown or not")
    showcompletionconditions: Optional[StrictBool] = Field(description="Whether the activity completion conditions are shown or not")
    sortorder: Optional[StrictInt] = Field(default=None, description="Sort order in the category")
    summary: Optional[StrictStr] = Field(description="summary")
    summaryfiles: Optional[List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner]] = Field(default=None, description="summary files in the summary field")
    summaryformat: Optional[StrictInt] = Field(description="summary format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    __properties: ClassVar[List[str]] = ["categoryid", "categoryname", "contacts", "courseimage", "customfields", "displayname", "enrollmentmethods", "fullname", "id", "overviewfiles", "shortname", "showactivitydates", "showcompletionconditions", "sortorder", "summary", "summaryfiles", "summaryformat"]

    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 CoreCourseSearchCoursesResponseCoursesInner 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 contacts (list)
        _items = []
        if self.contacts:
            for _item_contacts in self.contacts:
                if _item_contacts:
                    _items.append(_item_contacts.to_dict())
            _dict['contacts'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in customfields (list)
        _items = []
        if self.customfields:
            for _item_customfields in self.customfields:
                if _item_customfields:
                    _items.append(_item_customfields.to_dict())
            _dict['customfields'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in overviewfiles (list)
        _items = []
        if self.overviewfiles:
            for _item_overviewfiles in self.overviewfiles:
                if _item_overviewfiles:
                    _items.append(_item_overviewfiles.to_dict())
            _dict['overviewfiles'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in summaryfiles (list)
        _items = []
        if self.summaryfiles:
            for _item_summaryfiles in self.summaryfiles:
                if _item_summaryfiles:
                    _items.append(_item_summaryfiles.to_dict())
            _dict['summaryfiles'] = _items
        # set to None if categoryid (nullable) is None
        # and model_fields_set contains the field
        if self.categoryid is None and "categoryid" in self.model_fields_set:
            _dict['categoryid'] = None

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "categoryid": obj.get("categoryid"),
            "categoryname": obj.get("categoryname"),
            "contacts": [CoreCourseGetCoursesByFieldResponseCoursesInnerContactsInner.from_dict(_item) for _item in obj["contacts"]] if obj.get("contacts") is not None else None,
            "courseimage": obj.get("courseimage"),
            "customfields": [CoreCohortGetCohortsResponseInnerCustomfieldsInner.from_dict(_item) for _item in obj["customfields"]] if obj.get("customfields") is not None else None,
            "displayname": obj.get("displayname"),
            "enrollmentmethods": obj.get("enrollmentmethods"),
            "fullname": obj.get("fullname"),
            "id": obj.get("id"),
            "overviewfiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["overviewfiles"]] if obj.get("overviewfiles") is not None else None,
            "shortname": obj.get("shortname"),
            "showactivitydates": obj.get("showactivitydates"),
            "showcompletionconditions": obj.get("showcompletionconditions"),
            "sortorder": obj.get("sortorder"),
            "summary": obj.get("summary"),
            "summaryfiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["summaryfiles"]] if obj.get("summaryfiles") is not None else None,
            "summaryformat": obj.get("summaryformat")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


