import java.util.Date;

import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.cover.SessionManager;

/**
 * class to support Sakai Login headers sent in request as a string array
 */
public class SakaiSession {

    public String checkSession(String id) {
	System.out.println("session id="+id);
        Session s = SessionManager.getSession(id);
        if (s == null)
        {
        	System.out.println("no session established");
		return "Session Null";
        }
        else
        {
		String resp = "session: " + s.getId()
        		+ " user id: " + s.getUserId()
        		+ " user enterprise id: " + s.getUserEid()
        		+ " started: " + new Date(s.getCreationTime()).toLocaleString()
        		+ " accessed: " + new Date(s.getLastAccessedTime()).toLocaleString()
        		+ " inactive after: " + s.getMaxInactiveInterval();
        	System.out.println(resp);
		return resp;
        }
    }

    public String getSessionUser(String id) {
        Session s = SessionManager.getSession(id);
        if (s == null)
        {
		System.out.println("getSessionUser session id="+id+" Has no user");
		return "";
        }
        else
        {
		System.out.println("getSessionUser session id="+id+" eid="+s.getUserEid());
		return s.getUserEid();
        }
    }
}
