package com.google.sps.servlets;

import com.google.appengine.api.users.UserServiceFactory;
import com.google.sps.utilities.CommonUtils;
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/** Servlet that returns the login status of the user. */
@WebServlet("/login-status")
public class LoginStatusServlet extends HttpServlet {
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("application/json;");

    // Get the current login status.
    LoginStatus status;
    if (UserServiceFactory.getUserService().isUserLoggedIn()) {
      status = LoginStatus.getLoggedInInstance();
    } else {
      status = LoginStatus.getNotLoggedInInstance();
    }

    response.getWriter().println(CommonUtils.convertToJson(status));
  }

  private static class LoginStatus {
    private static final LoginStatus STATUS_LOGGED_IN = new LoginStatus(true);
    private static final LoginStatus STATUS_NOT_LOGGED_IN = new LoginStatus(false);
    private boolean isLoggedIn;

    private LoginStatus(boolean isLoggedIn) {
      this.isLoggedIn = isLoggedIn;
    }

    public static LoginStatus getLoggedInInstance() {
      return STATUS_LOGGED_IN;
    }

    public static LoginStatus getNotLoggedInInstance() {
      return STATUS_NOT_LOGGED_IN;
    }
  }
}

@@ -364,24 +364,43 @@
 rns 
-the login status
+whether user is logged in and email
  of 
@@ -660,45 +660,12 @@
 %22);%0A
-%0A
     
-// Get the current login status.
 %0A   
@@ -755,32 +755,36 @@
 %7B%0A      status =
+ new
  LoginStatus.get
@@ -783,29 +783,78 @@
 atus
-.getLoggedInInstance(
+(true, UserServiceFactory.getUserService().getCurrentUser().getEmail()
 );%0A 
@@ -879,16 +879,20 @@
 status =
+ new
  LoginSt
@@ -899,32 +899,18 @@
 atus
-.getNotLoggedInInstance(
+(false, %22%22
 );%0A 
@@ -999,23 +999,16 @@
 private 
-static 
 class Lo
@@ -1035,197 +1035,64 @@
 ate 
-static final LoginStatus STATUS_LOGGED_IN = new LoginStatus(true);%0A    private static final LoginStatus STATUS_NOT_LOGGED_IN = new LoginStatus(false);%0A    private boolean isLoggedIn
+boolean isLoggedIn;%0A    private String userEmail
 ;%0A%0A    p
 riva
@@ -1087,22 +1087,21 @@
 ;%0A%0A    p
-rivate
+ublic
  LoginSt
@@ -1123,16 +1123,34 @@
 LoggedIn
+, String userEmail
 ) %7B%0A    
@@ -1189,193 +1189,36 @@
     
-%7D%0A%0A    public static LoginStatus getLoggedInInstance() %7B%0A      return STATUS_LOGGED_IN;%0A    %7D%0A%0A    public static LoginStatus getNotLoggedInInstance() %7B%0A      return STATUS_NOT_LOGGED_IN
+  this.userEmail = userEmail
 ;%0A  

Add email field to login status.