package ch.mod_p.sre24.e5.data;

import android.content.Context;
import ch.mod_p.sre24.e5.data.Result;
import ch.mod_p.sre24.e5.data.model.LoggedInUser;

/* loaded from: classes.dex */
public class LoginRepository {
    private static volatile LoginRepository instance;
    private final LoginDataSource dataSource;
    private LoggedInUser user = null;

    private void setLoggedInUser(LoggedInUser loggedInUser) {
        this.user = loggedInUser;
    }

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

    private LoginRepository(LoginDataSource loginDataSource) {
        this.dataSource = loginDataSource;
    }

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

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

    public Result<LoggedInUser> login(Context context, String str, String str2) {
        Result<LoggedInUser> login = this.dataSource.login(context, str, str2);
        if (login instanceof Result.Success) {
            setLoggedInUser((LoggedInUser) ((Result.Success) login).getData());
        }
        return login;
    }
}
