from api.auth.keycloak_client import Keycloak
from core.get_value import get_value


class KeycloakUser:

    def __init__(self, source: dict):
        self._username = get_value(source, "preferred_username", str)
        self._email = get_value(source, "email", str)
        self._email_verified = get_value(source, "email_verified", bool)
        self._name = get_value(source, "name", str)

    @property
    def username(self) -> str:
        return self._username

    @property
    def email(self) -> str:
        return self._email

    @property
    def email_verified(self) -> bool:
        return self._email_verified

    @property
    def name(self) -> str:
        return self._name

    # Attrs from keycloak

    @property
    def id(self) -> str:
        return Keycloak.admin.get_user_id(self._username)
