package xyz.thepathfinder.android;

import com.google.gson.JsonObject;

public abstract class SubscribableCrudModel<E extends PathfinderListener> extends SubscribableModel<E> {

    public SubscribableCrudModel(PathfinderConnection connection) {
        super(connection);
    }

    public void connect() {
        JsonObject model = new JsonObject();
        model.addProperty("model", this.getModel());
        model.addProperty("id", this.getId());

        JsonObject json = new JsonObject();
        json.add("read", model);

        this.getConnection().sendMessage(json.toString());
    }

    public void create() {
        JsonObject model = new JsonObject();
        model.addProperty("model", this.getModel());
        model.add("value", this.toJson());

        JsonObject json = new JsonObject();
        json.add("create", model);

        this.getConnection().sendMessage(json.toString());
    }

    public void delete() {
        JsonObject model = new JsonObject();
        model.addProperty("model", this.getModel());
        model.addProperty("id", this.getId());

        JsonObject json = new JsonObject();
        json.add("delete", model);

        this.getConnection().sendMessage(json.toString());
    }

    public void update(JsonObject value) {
        //TODO implement
    }
}

@@ -458,33 +458,40 @@
      JsonObject 
-j
+requestJ
 son = new JsonOb
@@ -498,33 +498,40 @@
 ject();%0A        
-j
+requestJ
 son.add(%22read%22, 
@@ -572,33 +572,40 @@
 n().sendMessage(
-j
+requestJ
 son.toString());
@@ -792,33 +792,40 @@
      JsonObject 
-j
+requestJ
 son = new JsonOb
@@ -832,33 +832,40 @@
 ject();%0A        
-j
+requestJ
 son.add(%22create%22
@@ -908,33 +908,40 @@
 n().sendMessage(
-j
+requestJ
 son.toString());
@@ -1140,17 +1140,24 @@
 nObject 
-j
+requestJ
 son = ne
@@ -1180,17 +1180,24 @@
         
-j
+requestJ
 son.add(
@@ -1256,17 +1256,24 @@
 Message(
-j
+requestJ
 son.toSt
@@ -1343,24 +1343,340 @@
     
-//TODO implement
+JsonObject model = new JsonObject();%0A        model.addProperty(%22model%22, this.getModel());%0A        model.addProperty(%22id%22, this.getId());%0A        model.add(%22value%22, value);%0A%0A        JsonObject requestJson = new JsonObject();%0A        requestJson.add(%22update%22, model);%0A%0A        this.getConnection().sendMessage(requestJson.toString());
 %0A   

update requests should now work