# 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_enrol_get_enrolled_users_response_inner_enrolledcourses_inner import CoreEnrolGetEnrolledUsersResponseInnerEnrolledcoursesInner
from poodle_async_full.models.core_enrol_get_enrolled_users_response_inner_roles_inner import CoreEnrolGetEnrolledUsersResponseInnerRolesInner
from poodle_async_full.models.core_enrol_get_enrolled_users_with_capability_response_inner_users_inner_groups_inner import CoreEnrolGetEnrolledUsersWithCapabilityResponseInnerUsersInnerGroupsInner
from poodle_async_full.models.core_enrol_get_potential_users_response_inner_customfields_inner import CoreEnrolGetPotentialUsersResponseInnerCustomfieldsInner
from poodle_async_full.models.core_enrol_get_potential_users_response_inner_preferences_inner import CoreEnrolGetPotentialUsersResponseInnerPreferencesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModAssignListParticipantsResponseInner(BaseModel):
    """
    ModAssignListParticipantsResponseInner
    """ # noqa: E501
    address: Optional[StrictStr] = Field(default=None, description="Postal address")
    city: Optional[StrictStr] = Field(default=None, description="Home city of the user")
    country: Optional[StrictStr] = Field(default=None, description="Home country code of the user, such as AU or CZ")
    customfields: Optional[List[CoreEnrolGetPotentialUsersResponseInnerCustomfieldsInner]] = Field(default=None, description="User custom fields (also known as user profile fields)")
    department: Optional[StrictStr] = Field(default=None, description="department")
    description: Optional[StrictStr] = Field(default=None, description="User profile description")
    descriptionformat: Optional[StrictInt] = Field(default=None, description="int format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    email: Optional[StrictStr] = Field(default=None, description="Email address")
    enrolledcourses: Optional[List[CoreEnrolGetEnrolledUsersResponseInnerEnrolledcoursesInner]] = Field(default=None, description="Courses where the user is enrolled - limited by which courses the user is able to see")
    firstaccess: Optional[StrictInt] = Field(default=None, description="first access to the site (0 if never)")
    firstname: Optional[StrictStr] = Field(default=None, description="The first name(s) of the user")
    fullname: Optional[StrictStr] = Field(description="The fullname of the user")
    grantedextension: Optional[StrictBool] = Field(description="have they been granted an extension")
    groupid: Optional[StrictInt] = Field(default=None, description="for group assignments this is the group id")
    groupname: Optional[StrictStr] = Field(default=None, description="for group assignments this is the group name")
    groups: Optional[List[CoreEnrolGetEnrolledUsersWithCapabilityResponseInnerUsersInnerGroupsInner]] = Field(default=None, description="user groups")
    id: Optional[StrictInt] = Field(description="ID of the user")
    idnumber: Optional[StrictStr] = Field(default=None, description="The idnumber of the user")
    institution: Optional[StrictStr] = Field(default=None, description="institution")
    interests: Optional[StrictStr] = Field(default=None, description="user interests (separated by commas)")
    lastaccess: Optional[StrictInt] = Field(default=None, description="last access to the site (0 if never)")
    lastname: Optional[StrictStr] = Field(default=None, description="The family name of the user")
    phone1: Optional[StrictStr] = Field(default=None, description="Phone 1")
    phone2: Optional[StrictStr] = Field(default=None, description="Phone 2")
    preferences: Optional[List[CoreEnrolGetPotentialUsersResponseInnerPreferencesInner]] = Field(default=None, description="Users preferences")
    profileimageurl: Optional[StrictStr] = Field(default=None, description="User image profile URL - big version")
    profileimageurlsmall: Optional[StrictStr] = Field(default=None, description="User image profile URL - small version")
    recordid: Optional[StrictInt] = Field(description="record id")
    requiregrading: Optional[StrictBool] = Field(description="is their submission waiting for grading")
    roles: Optional[List[CoreEnrolGetEnrolledUsersResponseInnerRolesInner]] = Field(default=None, description="user roles")
    submissionstatus: Optional[StrictStr] = Field(default=None, description="The submission status (new, draft, reopened or submitted).                 Empty when not submitted.")
    submitted: Optional[StrictBool] = Field(description="have they submitted their assignment")
    suspended: Optional[StrictBool] = Field(default=None, description="Suspend user account, either false to enable user login or true to disable it")
    trackforums: Optional[StrictInt] = Field(default=None, description="Whether the user is tracking forums.")
    username: Optional[StrictStr] = Field(default=None, description="The username")
    __properties: ClassVar[List[str]] = ["address", "city", "country", "customfields", "department", "description", "descriptionformat", "email", "enrolledcourses", "firstaccess", "firstname", "fullname", "grantedextension", "groupid", "groupname", "groups", "id", "idnumber", "institution", "interests", "lastaccess", "lastname", "phone1", "phone2", "preferences", "profileimageurl", "profileimageurlsmall", "recordid", "requiregrading", "roles", "submissionstatus", "submitted", "suspended", "trackforums", "username"]

    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 ModAssignListParticipantsResponseInner 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 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 enrolledcourses (list)
        _items = []
        if self.enrolledcourses:
            for _item_enrolledcourses in self.enrolledcourses:
                if _item_enrolledcourses:
                    _items.append(_item_enrolledcourses.to_dict())
            _dict['enrolledcourses'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in groups (list)
        _items = []
        if self.groups:
            for _item_groups in self.groups:
                if _item_groups:
                    _items.append(_item_groups.to_dict())
            _dict['groups'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in preferences (list)
        _items = []
        if self.preferences:
            for _item_preferences in self.preferences:
                if _item_preferences:
                    _items.append(_item_preferences.to_dict())
            _dict['preferences'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in roles (list)
        _items = []
        if self.roles:
            for _item_roles in self.roles:
                if _item_roles:
                    _items.append(_item_roles.to_dict())
            _dict['roles'] = _items
        # set to None if address (nullable) is None
        # and model_fields_set contains the field
        if self.address is None and "address" in self.model_fields_set:
            _dict['address'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "address": obj.get("address"),
            "city": obj.get("city"),
            "country": obj.get("country"),
            "customfields": [CoreEnrolGetPotentialUsersResponseInnerCustomfieldsInner.from_dict(_item) for _item in obj["customfields"]] if obj.get("customfields") is not None else None,
            "department": obj.get("department"),
            "description": obj.get("description"),
            "descriptionformat": obj.get("descriptionformat"),
            "email": obj.get("email"),
            "enrolledcourses": [CoreEnrolGetEnrolledUsersResponseInnerEnrolledcoursesInner.from_dict(_item) for _item in obj["enrolledcourses"]] if obj.get("enrolledcourses") is not None else None,
            "firstaccess": obj.get("firstaccess"),
            "firstname": obj.get("firstname"),
            "fullname": obj.get("fullname"),
            "grantedextension": obj.get("grantedextension"),
            "groupid": obj.get("groupid"),
            "groupname": obj.get("groupname"),
            "groups": [CoreEnrolGetEnrolledUsersWithCapabilityResponseInnerUsersInnerGroupsInner.from_dict(_item) for _item in obj["groups"]] if obj.get("groups") is not None else None,
            "id": obj.get("id"),
            "idnumber": obj.get("idnumber"),
            "institution": obj.get("institution"),
            "interests": obj.get("interests"),
            "lastaccess": obj.get("lastaccess"),
            "lastname": obj.get("lastname"),
            "phone1": obj.get("phone1"),
            "phone2": obj.get("phone2"),
            "preferences": [CoreEnrolGetPotentialUsersResponseInnerPreferencesInner.from_dict(_item) for _item in obj["preferences"]] if obj.get("preferences") is not None else None,
            "profileimageurl": obj.get("profileimageurl"),
            "profileimageurlsmall": obj.get("profileimageurlsmall"),
            "recordid": obj.get("recordid"),
            "requiregrading": obj.get("requiregrading"),
            "roles": [CoreEnrolGetEnrolledUsersResponseInnerRolesInner.from_dict(_item) for _item in obj["roles"]] if obj.get("roles") is not None else None,
            "submissionstatus": obj.get("submissionstatus"),
            "submitted": obj.get("submitted"),
            "suspended": obj.get("suspended"),
            "trackforums": obj.get("trackforums"),
            "username": obj.get("username")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


