# coding: utf-8

"""
    Logto API references

    API references for Logto services.

    The version of the OpenAPI document: Cloud
    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
from typing import Any, ClassVar, Dict, List, Optional
from py_logto.models.get_jwt_customizer200_response_one_of_context_sample_user_profile import GetJwtCustomizer200ResponseOneOfContextSampleUserProfile
from py_logto.models.update_user_request_avatar import UpdateUserRequestAvatar
from py_logto.models.update_user_request_name import UpdateUserRequestName
from py_logto.models.update_user_request_primary_email import UpdateUserRequestPrimaryEmail
from py_logto.models.update_user_request_primary_phone import UpdateUserRequestPrimaryPhone
from py_logto.models.update_user_request_username import UpdateUserRequestUsername
from typing import Optional, Set
from typing_extensions import Self

class UpdateUserRequest(BaseModel):
    """
    UpdateUserRequest
    """ # noqa: E501
    username: Optional[UpdateUserRequestUsername] = None
    primary_email: Optional[UpdateUserRequestPrimaryEmail] = Field(default=None, alias="primaryEmail")
    primary_phone: Optional[UpdateUserRequestPrimaryPhone] = Field(default=None, alias="primaryPhone")
    name: Optional[UpdateUserRequestName] = None
    avatar: Optional[UpdateUserRequestAvatar] = None
    custom_data: Optional[Dict[str, Any]] = Field(default=None, description="Custom data object to update for the given user ID. Note this will replace the entire custom data object.  If you want to perform a partial update, use the `PATCH /api/users/{userId}/custom-data` endpoint instead.", alias="customData")
    profile: Optional[GetJwtCustomizer200ResponseOneOfContextSampleUserProfile] = None
    __properties: ClassVar[List[str]] = ["username", "primaryEmail", "primaryPhone", "name", "avatar", "customData", "profile"]

    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 UpdateUserRequest 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 username
        if self.username:
            _dict['username'] = self.username.to_dict()
        # override the default output from pydantic by calling `to_dict()` of primary_email
        if self.primary_email:
            _dict['primaryEmail'] = self.primary_email.to_dict()
        # override the default output from pydantic by calling `to_dict()` of primary_phone
        if self.primary_phone:
            _dict['primaryPhone'] = self.primary_phone.to_dict()
        # override the default output from pydantic by calling `to_dict()` of name
        if self.name:
            _dict['name'] = self.name.to_dict()
        # override the default output from pydantic by calling `to_dict()` of avatar
        if self.avatar:
            _dict['avatar'] = self.avatar.to_dict()
        # override the default output from pydantic by calling `to_dict()` of profile
        if self.profile:
            _dict['profile'] = self.profile.to_dict()
        # 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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "username": UpdateUserRequestUsername.from_dict(obj["username"]) if obj.get("username") is not None else None,
            "primaryEmail": UpdateUserRequestPrimaryEmail.from_dict(obj["primaryEmail"]) if obj.get("primaryEmail") is not None else None,
            "primaryPhone": UpdateUserRequestPrimaryPhone.from_dict(obj["primaryPhone"]) if obj.get("primaryPhone") is not None else None,
            "name": UpdateUserRequestName.from_dict(obj["name"]) if obj.get("name") is not None else None,
            "avatar": UpdateUserRequestAvatar.from_dict(obj["avatar"]) if obj.get("avatar") is not None else None,
            "customData": obj.get("customData"),
            "profile": GetJwtCustomizer200ResponseOneOfContextSampleUserProfile.from_dict(obj["profile"]) if obj.get("profile") is not None else None
        })
        return _obj


