# coding: utf-8

"""
    Coinbase Developer Platform APIs

    The Coinbase Developer Platform APIs - leading the world's transition onchain.

    The version of the OpenAPI document: 2.0.0
    Contact: cdp@coinbase.com
    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, field_validator
from typing import Any, ClassVar, Dict, List
from typing_extensions import Annotated
from cdp.openapi_client.models.authentication_method import AuthenticationMethod
from typing import Optional, Set
from typing_extensions import Self

class EndUser(BaseModel):
    """
    Information about the end user.
    """ # noqa: E501
    user_id: Annotated[str, Field(strict=True)] = Field(description="A stable, unique identifier for the end user. The `userId` must be unique across all end users in the developer's CDP Project. It must be between 1 and 100 characters long and can only contain alphanumeric characters and hyphens.", alias="userId")
    authentication_methods: List[AuthenticationMethod] = Field(description="The list of valid authentication methods linked to the end user.", alias="authenticationMethods")
    evm_accounts: List[Annotated[str, Field(strict=True)]] = Field(description="The list of EVM accounts associated with the end user. Currently, only one EVM account is supported per end user.", alias="evmAccounts")
    evm_smart_accounts: List[Annotated[str, Field(strict=True)]] = Field(description="The list of EVM smart accounts associated with the end user. Currently, only one EVM smart account is supported per end user.", alias="evmSmartAccounts")
    solana_accounts: List[Annotated[str, Field(strict=True)]] = Field(description="The list of Solana accounts associated with the end user. Currently, only one Solana account is supported per end user.", alias="solanaAccounts")
    __properties: ClassVar[List[str]] = ["userId", "authenticationMethods", "evmAccounts", "evmSmartAccounts", "solanaAccounts"]

    @field_validator('user_id')
    def user_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[a-zA-Z0-9-]{1,100}$", value):
            raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9-]{1,100}$/")
        return value

    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 EndUser 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 authentication_methods (list)
        _items = []
        if self.authentication_methods:
            for _item_authentication_methods in self.authentication_methods:
                if _item_authentication_methods:
                    _items.append(_item_authentication_methods.to_dict())
            _dict['authenticationMethods'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "userId": obj.get("userId"),
            "authenticationMethods": [AuthenticationMethod.from_dict(_item) for _item in obj["authenticationMethods"]] if obj.get("authenticationMethods") is not None else None,
            "evmAccounts": obj.get("evmAccounts"),
            "evmSmartAccounts": obj.get("evmSmartAccounts"),
            "solanaAccounts": obj.get("solanaAccounts")
        })
        return _obj


