package com.kodcu.rapid.path;

import com.kodcu.rapid.config.DockerClient;

import javax.json.JsonObject;
import javax.ws.rs.*;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.ExecutionException;

/**
 * Created by Hakan on 2/12/2016.
 */
@Path("volumes")
public class Volume extends DockerClient {

    @GET
    public String getVolumes(
            @QueryParam("filters") String filters)
            throws IOException, ExecutionException, InterruptedException {

        WebTarget target = resource().path("volumes");
        if (Objects.nonNull(filters))
            target = target.queryParam("filters", filters);

        Response response = getResponse(target);
        String entity = response.readEntity(String.class);
        response.close();
        return entity;
    }

    @GET
    @Path("{id}")
    public String inspectVolume(
            @PathParam("id") String name)
            throws IOException, ExecutionException, InterruptedException {

        WebTarget target = resource().path("volumes").path(name);

        Response response = getResponse(target);
        String entity = response.readEntity(String.class);
        response.close();
        return entity;
    }

    @DELETE
    @Path("{id}")
    public String deleteVolume(
            @PathParam("id") String name)
            throws IOException, ExecutionException, InterruptedException {

        WebTarget target = resource().path("volumes").path(name);

        Response response = deleteResponse(target);
        String entity = response.readEntity(String.class);
        response.close();
        return entity;
    }

    @POST
    @Path("create")
    public String createVolume(JsonObject content)
            throws IOException, ExecutionException, InterruptedException {

        WebTarget target = resource().path("volumes").path("create");

        Response response = postResponse(target, content);
        String entity = response.readEntity(String.class);
        response.close();
        return entity;
    }
}

@@ -970,36 +970,34 @@
 am(%22id%22) String 
-name
+id
 )%0A            th
@@ -1109,36 +1109,34 @@
 %22volumes%22).path(
-name
+id
 );%0A%0A        Resp
@@ -1385,19 +1385,88 @@
  String 
-nam
+id,%0A            @DefaultValue(%22false%22) @QueryParam(%22force%22) boolean forc
 e)%0A     
@@ -1599,11 +1599,36 @@
 ath(
-nam
+id).queryParam(%22force%22, forc
 e);%0A
@@ -1791,24 +1791,531 @@
 ity;%0A    %7D%0A%0A
+    @POST%0A    @Path(%22prune%22)%0A    public String pruneVolume(%0A            @QueryParam(%22filters%22) String filters)%0A            throws IOException, ExecutionException, InterruptedException %7B%0A%0A        WebTarget target = resource().path(%22volumes%22);%0A%0A        if (Objects.nonNull(filters))%0A            target = target.queryParam(%22filters%22, filters);%0A%0A        Response response = postResponse(target);%0A        String entity = response.readEntity(String.class);%0A        response.close();%0A        return entity;%0A    %7D%0A%0A
     @POST%0A  

update volume queries