package ge.edu.freeuni.sdp.iot.simulator.bath.service;

import ge.edu.freeuni.sdp.iot.simulator.bath.jaxb.LightSwitchPostRequest;
import ge.edu.freeuni.sdp.iot.simulator.bath.jaxb.VentSwitchPostRequest;
import ge.edu.freeuni.sdp.iot.simulator.bath.model.Bathroom;
import ge.edu.freeuni.sdp.iot.simulator.bath.model.VentSwitch;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/bath")
@Produces({MediaType.APPLICATION_JSON})
public class BathroomService {

    @POST
    @Path("/light-switch")
    public Response switchLight(final LightSwitchPostRequest request) {
        if (request.getStatus().equals("ON")) {
            Bathroom.getInstance().turnLightOn();
            return Response.ok().build();
        }
        else if (request.getStatus().equals("OFF")) {
            Bathroom.getInstance().turnLightOff();
            return Response.ok().build();
        }
        return null;
    }

    @POST
    @Path("/vent-switch/{action}")
    public VentSwitch switchVent(@PathParam("action") String action) {
        VentSwitch ventSwitch = Bathroom.getInstance().getVentSwitch();

        if (action.equals("ON")) {
            Bathroom.getInstance().turnVentOn();
            return ventSwitch;
        }
        else if (action.equals("OFF")) {
            Bathroom.getInstance().turnVentOff();
            return ventSwitch;
        }

        return null;
    }

    @GET
    @Path("/vent-switch")
    public VentSwitch switchVent() {
        VentSwitch ventSwitch = Bathroom.getInstance().getVentSwitch();
        
        return ventSwitch;
    }
}

@@ -1152,24 +1152,38 @@
 (action.
+toLowerCase().
 equals(%22
 ON%22)) %7B%0A
@@ -1166,34 +1166,34 @@
 rCase().equals(%22
-ON
+no
 %22)) %7B%0A          
@@ -1296,24 +1296,38 @@
 (action.
+toLowerCase().
 equals(%22
 OFF%22)) %7B
@@ -1310,35 +1310,35 @@
 rCase().equals(%22
-OFF
+off
 %22)) %7B%0A          

add lowercase convertion for action types