package de.yannicpunktdee.yoshibot.utils;

import lombok.Getter;
import net.dean.jraw.RedditClient;
import net.dean.jraw.http.NetworkAdapter;
import net.dean.jraw.http.OkHttpNetworkAdapter;
import net.dean.jraw.http.UserAgent;
import net.dean.jraw.oauth.Credentials;
import net.dean.jraw.oauth.OAuthHelper;

public final class RedditProvider {
	
	@Getter
	private static boolean isInit = false;
	
	private static RedditClient reddit;
	
	public static void init() {
		if (isInit) Logger.logWarning("RedditProvider wird reinitialisiert");
		
		String username = Resources.getRedditData().get("username");
		String password = Resources.getRedditData().get("password");
		String clientId = Resources.getRedditData().get("client_id");
		String clientSecret = Resources.getRedditData().get("client_secret");
		
		UserAgent userAgent = new UserAgent("bot", "de.yannicpunktdee.yoshibot", "v1", username);
		
		
		Credentials creds = Credentials.script(username, password, clientId, clientSecret);
		
		NetworkAdapter adapter = new OkHttpNetworkAdapter(userAgent);
		
		reddit = OAuthHelper.automatic(adapter, creds);
		
		isInit = true;
	}
	
}
