package welcomemat.lockpick;

import org.apache.commons.io.IOUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.HashMap;

public class Lockpick {
    Map<String, String> generateHeaders(String cookie) {
        return null;
    }

    Config getConfig() {
        return null;
    }

    void createConfig() {

    }

    // Nick
    PageInfo scrape(String path, String cookie, boolean getCookie) throws IOException {
        URL url = new URL(BASE_URL + path);
        HttpURLConnection http = (HttpURLConnection) url.openConnection();
        try {
            Map<String, String> headers = generateHeaders(cookie);
            for(String field : headers.keySet()) {
                http.setRequestProperty(field, headers.get(field));
            }
            IOUtils.toByteArray(http.getInputStream());
            Document soup = Jsoup.parse(http.getInputStream(), "UTF-8", url.toString());
            soup.
        } finally {
           http.disconnect();
        }
        return null;
    }

    // Allison
    String login(Config config){
        // Logs in to the huskycardcenter.neu.edu, returns the user's cookie
        PageInfo sesstokAndLoginCookie = scrape("/login/ldap.php", null, true);

        //maps the username and password to things in a hashmap for some reason
        Map<String, String> data = new HashMap<String, String>();
        data.put("User", config.getUsername());
        data.put("Pass", config.getPassword());

        String loginImportantString = "Holder"; // make this equal to things with requests later . . .
        String[] parts = loginImportantString.split(";");
        String cookie = parts[0];

        return cookie;
    }

    boolean testLogin(String cookie) {

    }

    void unlockDoor(String cookie) {
        //Takes the user's cookie, sends the request to unlock that door

        PageInfo doorSesstok = this.scrape("/student/openmydoor.php", cookie, false);
        Boolean room = true; //because only dealing with IV and not a suite
        Map<String, Boolean> data = new HashMap<String, Boolean>();
        data.put("doorType", room);
        data.put("answeredYes", true);
        String unlock = "Holder"; //here needs to go a request thing

        //and then we're done (the python has test things here)
    }

    Map<String, String> getArgs() {
       return null;
    }

    void unlock() {

    }

}

@@ -560,393 +560,79 @@
     
-URL url = new URL(BASE_URL + path);%0A        HttpURLConnection http = (HttpURLConnection) url.openConnection();%0A        try %7B%0A            Map%3CString, String%3E headers = generateHeaders(cookie);%0A            for(String field : headers.keySet()) %7B%0A                http.setRequestProperty(field, headers.get(field));%0A            %7D%0A            IOUtils.toByteArray(http.getInputStream());%0A    
+Response resp = Request.get(BASE_URL + path, generateHeaders(cookie));%0A
     
@@ -644,20 +644,19 @@
 ocument 
-soup
+doc
  = Jsoup
@@ -666,134 +666,33 @@
 rse(
-htt
+res
 p.get
-InputStream(), %22UTF-8%22, url.toString());%0A            soup.%0A        %7D finally %7B%0A           http.disconnect();%0A        %7D
+Text());%0A        
 %0A   

Refactor scrape