# 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 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

class CoreEnrolGetPotentialUsersResponseInner(BaseModel):
    """
    CoreEnrolGetPotentialUsersResponseInner
    """ # noqa: E501
    address: Optional[StrictStr] = Field(default=None, description="Postal address")
    auth: Optional[StrictStr] = Field(default=None, description="Auth plugins include manual, ldap, etc")
    calendartype: Optional[StrictStr] = Field(default=None, description="Calendar type such as \"gregorian\", must exist on server")
    city: Optional[StrictStr] = Field(default=None, description="Home city of the user")
    confirmed: Optional[StrictBool] = Field(default=None, description="Active user: 1 if confirmed, 0 otherwise")
    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="An email address - allow email as root@localhost")
    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")
    id: Optional[StrictInt] = Field(description="ID of the user")
    idnumber: Optional[StrictStr] = Field(default=None, description="An arbitrary ID code number perhaps from the institution")
    institution: Optional[StrictStr] = Field(default=None, description="institution")
    interests: Optional[StrictStr] = Field(default=None, description="user interests (separated by commas)")
    lang: Optional[StrictStr] = Field(default=None, description="Language code such as \"en\", must exist on server")
    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")
    mailformat: Optional[StrictInt] = Field(default=None, description="Mail format code is 0 for plain text, 1 for HTML etc")
    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(description="User image profile URL - big version")
    profileimageurlsmall: Optional[StrictStr] = Field(description="User image profile URL - small version")
    suspended: Optional[StrictBool] = Field(default=None, description="Suspend user account, either false to enable user login or true to disable it")
    theme: Optional[StrictStr] = Field(default=None, description="Theme name such as \"standard\", must exist on server")
    timezone: Optional[StrictStr] = Field(default=None, description="Timezone code such as Australia/Perth, or 99 for default")
    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", "auth", "calendartype", "city", "confirmed", "country", "customfields", "department", "description", "descriptionformat", "email", "firstaccess", "firstname", "fullname", "id", "idnumber", "institution", "interests", "lang", "lastaccess", "lastname", "mailformat", "phone1", "phone2", "preferences", "profileimageurl", "profileimageurlsmall", "suspended", "theme", "timezone", "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 CoreEnrolGetPotentialUsersResponseInner 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 preferences (list)
        _items = []
        if self.preferences:
            for _item_preferences in self.preferences:
                if _item_preferences:
                    _items.append(_item_preferences.to_dict())
            _dict['preferences'] = _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 auth (nullable) is None
        # and model_fields_set contains the field
        if self.auth is None and "auth" in self.model_fields_set:
            _dict['auth'] = None

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

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

        _obj = cls.model_validate({
            "address": obj.get("address"),
            "auth": obj.get("auth"),
            "calendartype": obj.get("calendartype"),
            "city": obj.get("city"),
            "confirmed": obj.get("confirmed"),
            "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"),
            "firstaccess": obj.get("firstaccess"),
            "firstname": obj.get("firstname"),
            "fullname": obj.get("fullname"),
            "id": obj.get("id"),
            "idnumber": obj.get("idnumber"),
            "institution": obj.get("institution"),
            "interests": obj.get("interests"),
            "lang": obj.get("lang"),
            "lastaccess": obj.get("lastaccess"),
            "lastname": obj.get("lastname"),
            "mailformat": obj.get("mailformat"),
            "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"),
            "suspended": obj.get("suspended"),
            "theme": obj.get("theme"),
            "timezone": obj.get("timezone"),
            "trackforums": obj.get("trackforums"),
            "username": obj.get("username")
        })
        return _obj


