// Path: app/src/main/java/uk/org/openseizuredetector/data/model/LoggedInUser.java
// public class LoggedInUser {
// 
//     private String userId;
//     private String displayName;
// 
//     public LoggedInUser(String userId, String displayName) {
//         this.userId = userId;
//         this.displayName = displayName;
//     }
// 
//     public String getUserId() {
//         return userId;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// }


import uk.org.openseizuredetector.data.model.LoggedInUser;
package uk.org.openseizuredetector.data;


/**
 * Class that requests authentication and user information from the remote data source and
 * maintains an in-memory cache of login status and user credentials information.
 */
public class LoginRepository {

    private static volatile LoginRepository instance;

    private LoginDataSource dataSource;

    // If user credentials will be cached in local storage, it is recommended it be encrypted
    // @see https://developer.android.com/training/articles/keystore
    private LoggedInUser user = null;

    // private constructor : singleton access
    private LoginRepository(LoginDataSource dataSource) {
        this.dataSource = dataSource;
    }

    public static LoginRepository getInstance(LoginDataSource dataSource) {
        if (instance == null) {
            instance = new LoginRepository(dataSource);
        }
        return instance;
    }

    public boolean isLoggedIn() {
        return user != null;
    }

    public void logout() {
        user = null;
// Path: app/src/main/java/uk/org/openseizuredetector/data/model/LoggedInUser.java
// public class LoggedInUser {
// 
//     private String userId;
//     private String displayName;
// 
//     public LoggedInUser(String userId, String displayName) {
//         this.userId = userId;
//         this.displayName = displayName;
//     }
// 
//     public String getUserId() {
//         return userId;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// }


// Path: app/src/main/java/uk/org/openseizuredetector/data/LoginRepository.java
import uk.org.openseizuredetector.data.model.LoggedInUser;

package uk.org.openseizuredetector.data;


/**
 * Class that requests authentication and user information from the remote data source and
 * maintains an in-memory cache of login status and user credentials information.
 */
public class LoginRepository {

    private static volatile LoginRepository instance;

    private LoginDataSource dataSource;

    // If user credentials will be cached in local storage, it is recommended it be encrypted
    // @see https://developer.android.com/training/articles/keystore
    private LoggedInUser user = null;

    // private constructor : singleton access
    private LoginRepository(LoginDataSource dataSource) {
        this.dataSource = dataSource;
    }

    public static LoginRepository getInstance(LoginDataSource dataSource) {
        if (instance == null) {
            instance = new LoginRepository(dataSource);
        }
        return instance;
    }

    public boolean isLoggedIn() {
        return user != null;
    }

    public void logout() {
        user = null;
        dataSource.logout();