package com.hubspot.baragon.service.resources;

import java.util.List;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.google.inject.Inject;
import com.hubspot.baragon.auth.NoAuth;
import com.hubspot.baragon.models.BaragonResponse;
import com.hubspot.baragon.service.managers.PurgeCacheManager;
import com.hubspot.baragon.service.managers.ServiceManager;
import com.hubspot.horizon.HttpResponse;

@Path("/purgeCache")
@Produces(MediaType.APPLICATION_JSON)
public class PurgeCacheResource {

  private final PurgeCacheManager purgeCacheManager;
  private final ServiceManager serviceManager;

  @Inject
  public PurgeCacheResource(PurgeCacheManager purgeCacheManager,
                            ServiceManager serviceManager){
    this.purgeCacheManager = purgeCacheManager;
    this.serviceManager = serviceManager;
  }

  @POST
  @NoAuth
  @Path("/sync/{serviceId}")
  public List<HttpResponse> purgeCache(@PathParam("serviceId") String serviceId) throws Exception {
    return purgeCacheManager.synchronouslyPurgeCache(serviceId);
  }

  @POST
  @NoAuth
  @Path("/{serviceId}")
  public BaragonResponse purgeCacheAsync(@PathParam("serviceId") String serviceId) {
    return serviceManager.enqueuePurgeCache(serviceId);
  }
}

@@ -45,32 +45,8 @@
 s;%0A%0A
-import java.util.List;%0A%0A
 impo
@@ -66,16 +66,16 @@
 s.POST;%0A
+
 import j
@@ -223,48 +223,8 @@
 ct;%0A
-import com.hubspot.baragon.auth.NoAuth;%0A
 impo
@@ -396,49 +396,8 @@
 ger;
-%0Aimport com.hubspot.horizon.HttpResponse;
 %0A%0A@P
@@ -815,32 +815,32 @@
 nager;%0A  %7D%0A%0A
+
   @POST%0A
   @NoAuth%0A  
@@ -831,235 +831,8 @@
 OST%0A
-  @NoAuth%0A  @Path(%22/sync/%7BserviceId%7D%22)%0A  public List%3CHttpResponse%3E purgeCache(@PathParam(%22serviceId%22) String serviceId) throws Exception %7B%0A    return purgeCacheManager.synchronouslyPurgeCache(serviceId);%0A  %7D%0A%0A  @POST%0A  @NoAuth%0A
   @P

Remove synchronous call to purgeCache from PurgeCacheResource