package de.szut.casino.security.oauth2;

import de.szut.casino.exceptionHandling.exceptions.OAuth2AuthenticationProcessingException;
import de.szut.casino.security.oauth2.github.GitHubOAuth2UserInfo;
import de.szut.casino.security.oauth2.google.GoogleOAuth2UserInfo;
import de.szut.casino.user.AuthProvider;

import java.util.Map;

public class OAuth2UserInfoFactory {

    public static OAuth2UserInfo getOAuth2UserInfo(String registrationId, Map<String, Object> attributes) {
        if (registrationId.equalsIgnoreCase(AuthProvider.GITHUB.toString())) {
            return new GitHubOAuth2UserInfo(attributes);
        } else if (registrationId.equalsIgnoreCase(AuthProvider.GOOGLE.toString())) {
            return new GoogleOAuth2UserInfo(attributes);
        } else {
            throw new OAuth2AuthenticationProcessingException("Sorry! Login with " + registrationId + " is not supported yet.");
        }
    }
}
