package openiss.ws.rest;

import openiss.Kinect;
import openiss.utils.PATCH;

import javax.activation.MimetypesFileTypeMap;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.MediaType;
import java.awt.datatransfer.MimeTypeParseException;
import java.io.File;

@Path("/openiss")
public class OpenISSRestService {


    static boolean mixFlag = false;
    static boolean cannyFlag = false;
    static boolean contourFlag = false;

    /**
     * Method handling HTTP GET requests. The returned object will be sent
     * to the client as "text/plain" media type.
     *
     * @return String that will be returned as a text/plain response.
     */
    @GET
    @Path("hello")
    @Produces(MediaType.TEXT_PLAIN)
    public String getIt() {
//        Kinect kinect = new Kinect();
//        kinect.initVideo();
//        BufferedImage someimage = kinect.getVideoImage();
        return "Hello World from Jersey API!";
    }

    private static String colorFileName = "src/api/java/openiss/ws/soap/service/color_example.jpg";
    private static String depthFileName = "src/api/java/openiss/ws/soap/service/depth_example.jpg";

    @GET
    @Path("/{type}")
    @Produces("image/*")
    public Response getImage(@PathParam(value = "type") String type) {

        File src;

        // validity checks
        if (!type.equals("color") && !type.equals("depth")) {
            return Response.noContent().build();
        }

        if(type.equals("color")) {
            src = new File(colorFileName);
        } else {
            src = new File(depthFileName);
        }

        String mt = new MimetypesFileTypeMap().getContentType(src);
        ResponseBuilder response = Response.ok(src, mt);
        return response.build();
    }

    @PATCH
    @Path("/mix")
    @Produces("text/plain")
    public String enableMix() {
        mixFlag = true;
        System.out.println("Mix enabled");
        return "mix enabled";
    }


    @DELETE
    @Path("/mix")
    @Produces("text/plain")
    public String disableMix() {
        mixFlag = false;
        return "mix disabled";
    }

    @PATCH
    @Path("/opencv/{type}")
    @Produces("text/plain")
    public String enableOpenCV(@PathParam(value = "type") String type) {

        // validity checks
        if (!type.equals("canny") && !type.equals("contour")) {
            return "Service not supported";
        }

        String response = "";
        if (type.equals("canny")) {
            cannyFlag = true;
            response = "canny enabled";
        } else if(type.equals("contour")) {
            contourFlag = true;
            response = "countour enabled";
        }
        return response;
    }


    @DELETE
    @Path("/opencv/{type}")
    @Produces("text/plain")
    public String disableOpenCV(@PathParam(value = "type") String type) {

        // validity checks
        if (!type.equals("canny") && !type.equals("contour")) {
            return "Service not supported.";
        }
        String response = "";
        if (type.equals("canny")) {
            cannyFlag = false;
            response = "canny disabled";
        } else if(type.equals("contour")) {
            contourFlag = false;
            response = "countour disabled";
        }
        return response;
    }



}

@@ -1395,21 +1395,19 @@
 equals(%22
-color
+rgb
 %22) && !t
@@ -1513,21 +1513,19 @@
 equals(%22
-color
+rgb
 %22)) %7B%0A  
@@ -1976,21 +1976,18 @@
 urn 
-%22mix enabled%22
+getFlags()
 ;%0A  
@@ -2127,22 +2127,18 @@
 urn 
-%22mix disabled%22
+getFlags()
 ;%0A  
@@ -2433,38 +2433,8 @@
  %7D%0A%0A
-        String response = %22%22;%0A
     
@@ -2499,48 +2499,8 @@
 ue;%0A
-            response = %22canny enabled%22;%0A
     
@@ -2575,51 +2575,8 @@
 ue;%0A
-            response = %22countour enabled%22;%0A
     
@@ -2592,32 +2592,34 @@
      return 
-response
+getFlags()
 ;%0A    %7D%0A%0A%0A  
@@ -2777,32 +2777,33 @@
  validity checks
+X
 %0A        if (!ty
@@ -2910,38 +2910,8 @@
   %7D%0A
-        String response = %22%22;%0A
     
@@ -2977,49 +2977,8 @@
 se;%0A
-            response = %22canny disabled%22;%0A
     
@@ -3062,43 +3062,192 @@
     
-    response = %22countour disabled%22;
+%7D%0A        return getFlags();%0A    %7D%0A%0A    private String getFlags() %7B%0A        String flags = %22Mix: %22 + String.valueOf(mixFlag) +%0A                %22%5CnCanny: %22 + String.valueOf(cannyFlag) +
 %0A   
@@ -3247,34 +3247,32 @@
 ) +%0A        
-%7D%0A
         
 return respo
@@ -3259,31 +3259,81 @@
         
-return response
+%22%5CnContour: %22 + String.valueOf(contourFlag);%0A        return flags
 ;%0A    %7D%0A

Fix path color to rgb