package it.com.atlassian.bitbucket.mirror;

import com.atlassian.bitbucket.rest.util.ResponseFactory;
import com.atlassian.bitbucket.rest.util.RestUtils;
import com.atlassian.bitbucket.util.DevModeUtils;
import com.atlassian.plugins.rest.common.security.AnonymousAllowed;
import com.sun.jersey.spi.resource.Singleton;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@AnonymousAllowed
@Consumes({MediaType.APPLICATION_JSON})
@Path("test-support")
@Produces({RestUtils.APPLICATION_JSON_UTF8})
@Singleton
public class TestSupportResource {

    @GET
    @Path("dev-mode")
    public Response getDevMode() {
        return ResponseFactory.ok()
                .entity(DevModeUtils.isEnabled())
                .build();
    }

    @PUT
    @Path("dev-mode/{value}")
    public Response setDevMode(@PathParam(value = "value") String value) {
        System.setProperty(DevModeUtils.ATLASSIAN_DEV_MODE, value);
        return ResponseFactory.noContent().build();
    }
}
