package net.contargo.iris.monitoring;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @author David Schilling - schilling@synyx.de
 */
@Aspect
@Component
public class PerformanceInterceptor {

    private final PerformanceStats performanceStats;

    @Autowired
    public PerformanceInterceptor(PerformanceStats performanceStats) {

        this.performanceStats = performanceStats;
    }

    @Around(
                "routeEnricherApiControllerGetEnrichedRoute() || "
                +   "addressApiControllerAddressesByAddressDetails()"
    )
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {

        long start = System.currentTimeMillis();

        try {
            return joinPoint.proceed();
        } finally {
            performanceStats.updateStats(joinPoint.getSourceLocation().getWithinType().getSimpleName() + "@"
                + joinPoint.getSignature().getName(), System.currentTimeMillis() - start);
        }
    }




    @Pointcut("execution(* net.contargo.iris.route.api.RouteEnricherApiController.getEnrichedRoute(..))")
    public void routeEnricherApiControllerGetEnrichedRoute() {

        // intercepts routeEnricherApiControllerGetEnrichedRoute
    }


    @Pointcut("execution(* net.contargo.iris.address.api.AddressApiController.addressesByAddressDetails(..))")
    public void addressApiControllerAddressesByAddressDetails() {

        // intercepts routeEnricherApiControllerGetEnrichedRoute
    }
}

@@ -208,16 +208,17 @@
 intcut;%0A
+%0A
 import o
@@ -272,16 +272,17 @@
 owired;%0A
+%0A
 import o
@@ -339,16 +339,17 @@
 @author 
+ 
 David Sc
@@ -650,24 +650,16 @@
 Around(%0A
-        
         
@@ -721,19 +721,9 @@
     
-        +  
++
  %22ad
@@ -1195,18 +1195,16 @@
     %7D%0A%0A%0A
-%0A%0A
     @Poi
@@ -1642,50 +1642,292 @@
 pts 
-routeEnricherApiControllerGetEnrichedRoute
+addressApiControllerAddressesByAddressDetails%0A    %7D%0A%0A%0A    @Pointcut(%22execution(* net.contargo.iris.address.api.AddressApiController.addressByGeolocation(..))%22)%0A    public void addressApiControllerAddressByGeolocation() %7B%0A%0A        // intercepts addressApiControllerAddressByGeolocation
 %0A   

add reverse geocode api to monitoring