package edu.cmu.sbs.hub.server;

import com.github.kevinsawicki.http.HttpRequest;

public class Action {

    final private static String bioIP = "localhost";
    final private static int bioPort = 23333;
    final private static String injectionURL = "/patient/injection";
    final private static String machineURL = "/anesthesia_machine";


    public static boolean kill() {
        HttpRequest.post(getURL(bioIP, bioPort, injectionURL)).send("{drug_name:'Succinylcholine', dose: 200000.0, concentration: 100.0}").code();

        return true;
    }

    public static boolean revive() {

        // TODO revive

        return true;
    }

    public static boolean noOxygen() {
        HttpRequest
        		.post(getURL(bioIP, bioPort, machineURL))
        		.send("{oxygen_fraction:0, status: false}")
        		.code();
        return true;
    }

    public static boolean resumeOxygen() {
        HttpRequest
        		.post(getURL(bioIP, bioPort, machineURL))
        		.send("{oxygen_fraction:0.5, status: true}")
        		.code();
        return true;
    }
    
    public static boolean inject(String drugName, Double dose) {
    	HttpRequest
    			.post(getURL(bioIP, bioPort, machineURL))
    			.send(String.format("{drug_name:'%s', dose: %f, concentration: 20.0}", drugName, dose))
    			.code();
    	return true;
    }

    private static String getURL(String ip, int port, String url) {
        return "http://" + ip + ":" + port + url;
    }
}

@@ -442,16 +442,18 @@
 .send(%22%7B
+%5C%22
 drug_nam
@@ -453,18 +453,21 @@
 rug_name
-:'
+%5C%22:%5C%22
 Succinyl
@@ -477,27 +477,33 @@
 line
-', 
+%5C%22, %5C%22
 dose
+%5C%22
 : 20000
-0
 .0, 
+%5C%22
 conc
@@ -511,16 +511,18 @@
 ntration
+%5C%22
 : 100.0%7D
@@ -1219,19 +1219,28 @@
 L))%0A    
-%09%09%09
+            
 .send(St
@@ -1253,16 +1253,18 @@
 ormat(%22%7B
+%5C%22
 drug_nam
@@ -1268,25 +1268,35 @@
 name
-:'%25s', 
+%5C%22:%5C%22%25s%5C%22, %5C%22
 dose
+%5C%22
 : %25f, 
+%5C%22
 conc
@@ -1304,16 +1304,18 @@
 ntration
+%5C%22
 : 20.0%7D%22
@@ -1337,19 +1337,28 @@
 e))%0A    
-%09%09%09
+            
 .code();

fix Action format bug: " escape