# coding: utf-8

"""
    DUPR Backend APIs

    Internal RESTful APIs to access DUPR ratings, users and provide matches.

    The version of the OpenAPI document: v1.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 date, datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from dupr_backend.models.granted_authority import GrantedAuthority
from dupr_backend.models.role import Role
from typing import Optional, Set
from typing_extensions import Self

class User(BaseModel):
    """
    User
    """ # noqa: E501
    id: Optional[StrictInt] = None
    full_name: StrictStr = Field(alias="fullName")
    first_name: Optional[StrictStr] = Field(default=None, alias="firstName")
    last_name: Optional[StrictStr] = Field(default=None, alias="lastName")
    email: StrictStr
    is_valid_email: Optional[StrictBool] = Field(default=None, alias="isValidEmail")
    secret: Optional[StrictStr] = None
    iso_code: Optional[StrictStr] = Field(default=None, alias="isoCode")
    phone_number: Optional[StrictStr] = Field(default=None, alias="phoneNumber")
    is_valid_phone: Optional[StrictBool] = Field(default=None, alias="isValidPhone")
    nickname: Optional[StrictStr] = None
    display_username: StrictBool = Field(alias="displayUsername")
    media_id: Optional[StrictInt] = Field(default=None, alias="mediaId")
    image_url: Optional[StrictStr] = Field(default=None, alias="imageUrl")
    referral_code: Optional[StrictStr] = Field(default=None, alias="referralCode")
    gender: Optional[StrictStr] = None
    birthdate: Optional[date] = None
    hand: Optional[StrictStr] = None
    role: Optional[Role] = None
    customer_key: Optional[StrictStr] = Field(default=None, alias="customerKey")
    status: Optional[StrictStr] = None
    created: Optional[datetime] = None
    external_id: Optional[StrictStr] = Field(default=None, alias="externalId")
    restricted: Optional[StrictBool] = None
    reliability_score: Optional[StrictInt] = Field(default=None, alias="reliabilityScore")
    lucra_connected: Optional[StrictBool] = Field(default=None, alias="lucraConnected")
    is_enabled: StrictBool = Field(alias="isEnabled")
    password: StrictStr
    authorities: List[GrantedAuthority]
    is_account_non_expired: StrictBool = Field(alias="isAccountNonExpired")
    is_account_non_locked: StrictBool = Field(alias="isAccountNonLocked")
    is_credentials_non_expired: StrictBool = Field(alias="isCredentialsNonExpired")
    username: StrictStr
    is_admin: StrictBool = Field(alias="isAdmin")
    valid_email: Optional[StrictBool] = Field(default=None, alias="validEmail")
    valid_phone: Optional[StrictBool] = Field(default=None, alias="validPhone")
    __properties: ClassVar[List[str]] = ["id", "fullName", "firstName", "lastName", "email", "isValidEmail", "secret", "isoCode", "phoneNumber", "isValidPhone", "nickname", "displayUsername", "mediaId", "imageUrl", "referralCode", "gender", "birthdate", "hand", "role", "customerKey", "status", "created", "externalId", "restricted", "reliabilityScore", "lucraConnected", "isEnabled", "password", "authorities", "isAccountNonExpired", "isAccountNonLocked", "isCredentialsNonExpired", "username", "isAdmin", "validEmail", "validPhone"]

    @field_validator('gender')
    def gender_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['MALE', 'FEMALE']):
            raise ValueError("must be one of enum values ('MALE', 'FEMALE')")
        return value

    @field_validator('hand')
    def hand_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['RIGHT', 'LEFT', 'BOTH', 'NONE']):
            raise ValueError("must be one of enum values ('RIGHT', 'LEFT', 'BOTH', 'NONE')")
        return value

    @field_validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['ACTIVE', 'INACTIVE', 'UPCOMING', 'IN_PROGRESS', 'COMPLETE', 'CANCELLED', 'NOT_CONFIRMED', 'INVITED', 'CONFIRMED', 'MATCH_BYE', 'PENDING', 'FORFEITED', 'DELETED', 'ONGOING', 'SUSPENDED_TOS_13']):
            raise ValueError("must be one of enum values ('ACTIVE', 'INACTIVE', 'UPCOMING', 'IN_PROGRESS', 'COMPLETE', 'CANCELLED', 'NOT_CONFIRMED', 'INVITED', 'CONFIRMED', 'MATCH_BYE', 'PENDING', 'FORFEITED', 'DELETED', 'ONGOING', 'SUSPENDED_TOS_13')")
        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 User 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 role
        if self.role:
            _dict['role'] = self.role.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in authorities (list)
        _items = []
        if self.authorities:
            for _item_authorities in self.authorities:
                if _item_authorities:
                    _items.append(_item_authorities.to_dict())
            _dict['authorities'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "fullName": obj.get("fullName"),
            "firstName": obj.get("firstName"),
            "lastName": obj.get("lastName"),
            "email": obj.get("email"),
            "isValidEmail": obj.get("isValidEmail"),
            "secret": obj.get("secret"),
            "isoCode": obj.get("isoCode"),
            "phoneNumber": obj.get("phoneNumber"),
            "isValidPhone": obj.get("isValidPhone"),
            "nickname": obj.get("nickname"),
            "displayUsername": obj.get("displayUsername"),
            "mediaId": obj.get("mediaId"),
            "imageUrl": obj.get("imageUrl"),
            "referralCode": obj.get("referralCode"),
            "gender": obj.get("gender"),
            "birthdate": obj.get("birthdate"),
            "hand": obj.get("hand"),
            "role": Role.from_dict(obj["role"]) if obj.get("role") is not None else None,
            "customerKey": obj.get("customerKey"),
            "status": obj.get("status"),
            "created": obj.get("created"),
            "externalId": obj.get("externalId"),
            "restricted": obj.get("restricted"),
            "reliabilityScore": obj.get("reliabilityScore"),
            "lucraConnected": obj.get("lucraConnected"),
            "isEnabled": obj.get("isEnabled"),
            "password": obj.get("password"),
            "authorities": [GrantedAuthority.from_dict(_item) for _item in obj["authorities"]] if obj.get("authorities") is not None else None,
            "isAccountNonExpired": obj.get("isAccountNonExpired"),
            "isAccountNonLocked": obj.get("isAccountNonLocked"),
            "isCredentialsNonExpired": obj.get("isCredentialsNonExpired"),
            "username": obj.get("username"),
            "isAdmin": obj.get("isAdmin"),
            "validEmail": obj.get("validEmail"),
            "validPhone": obj.get("validPhone")
        })
        return _obj


