# 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_user_create_users_parameters_users_inner_customfields_inner import CoreUserCreateUsersParametersUsersInnerCustomfieldsInner
from poodle_async_full.models.core_user_create_users_parameters_users_inner_preferences_inner import CoreUserCreateUsersParametersUsersInnerPreferencesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreUserUpdateUsersParametersUsersInner(BaseModel):
    """
    CoreUserUpdateUsersParametersUsersInner
    """ # noqa: E501
    address: Optional[StrictStr] = Field(default=None, description="Postal address")
    alternatename: Optional[StrictStr] = Field(default=None, description="The alternate name of the user")
    auth: Optional[StrictStr] = Field(default='', description="Auth plugins include manual, ldap, etc")
    calendartype: Optional[StrictStr] = Field(default='', description="Calendar type such as \"gregorian\", must exist on server")
    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[CoreUserCreateUsersParametersUsersInnerCustomfieldsInner]] = Field(default=None, description="User custom fields (also known as user profil fields)")
    department: Optional[StrictStr] = Field(default=None, description="Department")
    description: Optional[StrictStr] = Field(default=None, description="User profile description, no HTML")
    email: Optional[StrictStr] = Field(default='', description="A valid and unique email address")
    firstname: Optional[StrictStr] = Field(default='', description="The first name(s) of the user")
    firstnamephonetic: Optional[StrictStr] = Field(default=None, description="The first name(s) phonetically 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='', description="Language code such as \"en\", must exist on server")
    lastname: Optional[StrictStr] = Field(default=None, description="The family name of the user")
    lastnamephonetic: Optional[StrictStr] = Field(default=None, description="The family name phonetically of the user")
    maildisplay: Optional[StrictInt] = Field(default=None, description="Email visibility")
    mailformat: Optional[StrictInt] = Field(default=None, description="Mail format code is 0 for plain text, 1 for HTML etc")
    middlename: Optional[StrictStr] = Field(default=None, description="The middle name of the user")
    password: Optional[StrictStr] = Field(default='', description="Plain text password consisting of any characters")
    phone1: Optional[StrictStr] = Field(default=None, description="Phone")
    phone2: Optional[StrictStr] = Field(default=None, description="Mobile phone")
    preferences: Optional[List[CoreUserCreateUsersParametersUsersInnerPreferencesInner]] = Field(default=None, description="User preferences")
    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")
    username: Optional[StrictStr] = Field(default='', description="Username policy is defined in Moodle security config.")
    userpicture: Optional[StrictInt] = Field(default=None, description="The itemid where the new user picture has been uploaded to, 0 to delete")
    __properties: ClassVar[List[str]] = ["address", "alternatename", "auth", "calendartype", "city", "country", "customfields", "department", "description", "email", "firstname", "firstnamephonetic", "id", "idnumber", "institution", "interests", "lang", "lastname", "lastnamephonetic", "maildisplay", "mailformat", "middlename", "password", "phone1", "phone2", "preferences", "suspended", "theme", "timezone", "username", "userpicture"]

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

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

        return _dict

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

        relaxed = settings.relaxe_all_models or "CoreUserUpdateUsersParametersUsersInner" 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"),
            "alternatename": obj.get("alternatename"),
            "auth": obj.get("auth") if obj.get("auth") is not None else '',
            "calendartype": obj.get("calendartype") if obj.get("calendartype") is not None else '',
            "city": obj.get("city"),
            "country": obj.get("country"),
            "customfields": [CoreUserCreateUsersParametersUsersInnerCustomfieldsInner.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"),
            "email": obj.get("email") if obj.get("email") is not None else '',
            "firstname": obj.get("firstname") if obj.get("firstname") is not None else '',
            "firstnamephonetic": obj.get("firstnamephonetic"),
            "id": obj.get("id"),
            "idnumber": obj.get("idnumber"),
            "institution": obj.get("institution"),
            "interests": obj.get("interests"),
            "lang": obj.get("lang") if obj.get("lang") is not None else '',
            "lastname": obj.get("lastname"),
            "lastnamephonetic": obj.get("lastnamephonetic"),
            "maildisplay": obj.get("maildisplay"),
            "mailformat": obj.get("mailformat"),
            "middlename": obj.get("middlename"),
            "password": obj.get("password") if obj.get("password") is not None else '',
            "phone1": obj.get("phone1"),
            "phone2": obj.get("phone2"),
            "preferences": [CoreUserCreateUsersParametersUsersInnerPreferencesInner.from_dict(_item) for _item in obj["preferences"]] if obj.get("preferences") is not None else None,
            "suspended": obj.get("suspended"),
            "theme": obj.get("theme"),
            "timezone": obj.get("timezone"),
            "username": obj.get("username") if obj.get("username") is not None else '',
            "userpicture": obj.get("userpicture")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


