from allauth.socialaccount import providers
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider


class TeamsnapAccount(ProviderAccount):
    pass


class TeamsnapProvider(OAuth2Provider):
    id = "teamsnap"
    name = "TeamSnap"
    account_class = TeamsnapAccount

    def extract_uid(self, data):
        return str(data["id"])

    def extract_common_fields(self, data):
        return dict(
            username=data["email"],
            email=data["email"],
            first_name=data["first_name"],
            last_name=data["last_name"],
        )

    def get_default_scope(self):
        scope = ["read"]
        return scope


providers.registry.register(TeamsnapProvider)
