package com.timostaudinger.dailydose.model.dao;

import com.timostaudinger.dailydose.exception.RedditAuthException;
import com.timostaudinger.dailydose.util.Properties;
import com.timostaudinger.dailydose.util.Version;
import net.dean.jraw.http.LoggingMode;
import net.dean.jraw.http.UserAgent;
import net.dean.jraw.http.oauth.Credentials;
import net.dean.jraw.http.oauth.OAuthData;
import net.dean.jraw.http.oauth.OAuthException;

import java.util.UUID;

class RedditClient extends net.dean.jraw.RedditClient {

    private static final String PLATFORM = Properties.get("reddit_platform");
    private static final String APP_ID = Properties.get("reddit_app_id");
    private static final String VERSION = Version.get();
    private static final String USERNAME = Properties.get("reddit_username");
    private static final String CLIENT_ID = Properties.get("reddit_client_id");
    private static final String CLIENT_SECRET = Properties.get("reddit_client_secret");

    private static RedditClient instance;

    private RedditClient(UserAgent userAgent) {
        super(userAgent);
    }

    static RedditClient getInstance() throws RedditAuthException {
        if (instance == null || !instance.isAuthenticated()) {
            instance = createRedditClient();
        }

        return instance;
    }

    private static RedditClient createRedditClient() throws RedditAuthException {
        UserAgent userAgent = UserAgent.of(PLATFORM, APP_ID, VERSION, USERNAME);
        Credentials credentials = Credentials.userless(CLIENT_ID, CLIENT_SECRET, UUID.randomUUID());
        RedditClient redditClient = new RedditClient(userAgent);
        redditClient.setLoggingMode(LoggingMode.ON_FAIL);
        try {
            OAuthData authData = redditClient.getOAuthHelper().easyAuth(credentials);
            redditClient.authenticate(authData);
        } catch (OAuthException e) {
            throw new RedditAuthException("Could not authorize application", e);
        }

        return redditClient;
    }
}

@@ -472,43 +472,8 @@
 ent 
-extends net.dean.jraw.RedditClient 
 %7B%0A%0A 
@@ -986,69 +986,84 @@
 ate 
-RedditClient(UserAgent userAgent) %7B%0A        super(userAgent);
+static net.dean.jraw.RedditClient jrawClient;%0A%0A    private RedditClient() %7B%0A
 %0A   
@@ -1069,32 +1069,46 @@
   %7D%0A%0A    static 
+net.dean.jraw.
 RedditClient get
@@ -1180,24 +1180,26 @@
 ull %7C%7C !
-instance
+jrawClient
 .isAuthe
@@ -1283,24 +1283,26 @@
  return 
-instance
+jrawClient
 ;%0A    %7D%0A
@@ -1602,24 +1602,79 @@
 lient = new 
+RedditClient();%0A        jrawClient = new net.dean.jraw.
 RedditClient
@@ -1690,30 +1690,28 @@
 t);%0A        
-reddit
+jraw
 Client.setLo
@@ -1789,22 +1789,20 @@
 hData = 
-reddit
+jraw
 Client.g
@@ -1852,22 +1852,20 @@
         
-reddit
+jraw
 Client.a

Replace inheritance with composition in RedditClient class.