package ge.edu.freeuni.sdp.iot.service.camera_object_recognizer.proxy;

import ge.edu.freeuni.sdp.iot.service.camera_object_recognizer.model.ServiceState;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.jackson.JacksonFeature;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

public class CameraProxy {

    // TODO set values
    private static final String REAL_CAMERA_API =
            "";
    private static final String DEV_CAMERA_API =
            "";

    private final Client client;
    private final ServiceState state;

    public CameraProxy(ServiceState state) {
        this.state = state;
        ClientConfig config = new ClientConfig().register(JacksonFeature.class);
        this.client = ClientBuilder.newClient(config);
    }

    private String getApiUrl() {
        String apiUrl= null;

        if (state == ServiceState.DEV)
            apiUrl = DEV_CAMERA_API;
        else if (state == ServiceState.REAL)
            apiUrl = REAL_CAMERA_API;

        return apiUrl;
    }

    public byte[] get(String houseId) {
        // TODO add real implemetation
        return new byte[0];
    }
}

@@ -324,16 +324,85 @@
 Builder;
+%0Aimport javax.ws.rs.core.MediaType;%0Aimport javax.ws.rs.core.Response;
 %0A%0Apublic
@@ -427,31 +427,8 @@
  %7B%0A%0A
-    // TODO set values%0A
     
@@ -551,16 +551,65 @@
        %22
+https://iot-garden-simulator.herokuapp.com/webapi
 %22;%0A%0A    
@@ -1197,47 +1197,327 @@
     
-// TODO add real implemetation%0A
+String requestUrl = String.format(%22%25s/houses/%25s/camera%22, getApiUrl(), houseId);%0A        Response response = client%0A                .target(requestUrl)%0A                .request(MediaType.APPLICATION_OCTET_STREAM)%0A                .get();%0A%0A        byte%5B%5D ret = null;%0A%0A        if (ResponseUtils.is200(response))%0A   
         
 retu
@@ -1516,26 +1516,69 @@
     
+ 
 ret
-urn new byte%5B0%5D
+ = response.readEntity(byte%5B%5D.class);%0A%0A        return ret
 ;%0A  

Implement CameraProxy