# coding: utf-8

"""
    Identity Provider - Admin API

    Admin API endpoints (public tenant only)

    The version of the OpenAPI document: 1.0.0
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from binoauth.admin.models.external_account import ExternalAccount
from binoauth.admin.models.user_status import UserStatus
from typing import Optional, Set
from typing_extensions import Self

class UserWithExternalAccounts(BaseModel):
    """
    UserWithExternalAccounts
    """ # noqa: E501
    email: StrictStr
    name: Optional[StrictStr] = None
    is_active: Optional[StrictBool] = True
    email_verified: Optional[StrictBool] = False
    id: StrictStr
    nickname: Optional[StrictStr] = None
    full_name: Optional[StrictStr] = None
    first_name: Optional[StrictStr] = None
    last_name: Optional[StrictStr] = None
    picture: Optional[StrictStr] = None
    status: Optional[UserStatus] = None
    is_mfa_enabled: Optional[StrictBool] = False
    last_login: Optional[datetime] = None
    logins_count: Optional[StrictInt] = 0
    last_password_reset: Optional[datetime] = None
    last_ip: Optional[StrictStr] = None
    reset_password_on_login: Optional[StrictBool] = False
    created_at: datetime
    updated_at: datetime
    external_accounts: List[ExternalAccount]
    __properties: ClassVar[List[str]] = ["email", "name", "is_active", "email_verified", "id", "nickname", "full_name", "first_name", "last_name", "picture", "status", "is_mfa_enabled", "last_login", "logins_count", "last_password_reset", "last_ip", "reset_password_on_login", "created_at", "updated_at", "external_accounts"]

    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 UserWithExternalAccounts 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 external_accounts (list)
        _items = []
        if self.external_accounts:
            for _item_external_accounts in self.external_accounts:
                if _item_external_accounts:
                    _items.append(_item_external_accounts.to_dict())
            _dict['external_accounts'] = _items
        # 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 nickname (nullable) is None
        # and model_fields_set contains the field
        if self.nickname is None and "nickname" in self.model_fields_set:
            _dict['nickname'] = None

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "email": obj.get("email"),
            "name": obj.get("name"),
            "is_active": obj.get("is_active") if obj.get("is_active") is not None else True,
            "email_verified": obj.get("email_verified") if obj.get("email_verified") is not None else False,
            "id": obj.get("id"),
            "nickname": obj.get("nickname"),
            "full_name": obj.get("full_name"),
            "first_name": obj.get("first_name"),
            "last_name": obj.get("last_name"),
            "picture": obj.get("picture"),
            "status": obj.get("status"),
            "is_mfa_enabled": obj.get("is_mfa_enabled") if obj.get("is_mfa_enabled") is not None else False,
            "last_login": obj.get("last_login"),
            "logins_count": obj.get("logins_count") if obj.get("logins_count") is not None else 0,
            "last_password_reset": obj.get("last_password_reset"),
            "last_ip": obj.get("last_ip"),
            "reset_password_on_login": obj.get("reset_password_on_login") if obj.get("reset_password_on_login") is not None else False,
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "external_accounts": [ExternalAccount.from_dict(_item) for _item in obj["external_accounts"]] if obj.get("external_accounts") is not None else None
        })
        return _obj
