package org.ncomet.fibonaccispringaop.resource;

import org.ncomet.fibonaccispringaop.service.FibonacciService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.MessageFormat;

@RestController
@RequestMapping("/fibonacci/{n}")
public class FibonacciResource {

    private final FibonacciService fibonacciService;

    @Autowired
    public FibonacciResource(FibonacciService fibonacciService) {
        this.fibonacciService = fibonacciService;
    }

    @GetMapping
    public ResponseEntity<String> fibo(@PathVariable int n) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        long result = fibonacciService.compute(n);
        stopWatch.stop();
        StopWatch stopWatch2 = new StopWatch();
        stopWatch2.start();
        fibonacciService.compute(n);
        stopWatch2.stop();
        return ResponseEntity.ok(MessageFormat.format(
                "fibonacci({0}) = {1}<br/> The first time, it took {2}ms <br/>The second time, {3}ms",
                n,
                result,
                stopWatch.getLastTaskTimeMillis(),
                stopWatch2.getLastTaskTimeMillis()));
    }
}

@@ -932,32 +932,33 @@
 ew StopWatch();%0A
+%0A
         stopWatc
@@ -1045,24 +1045,25 @@
 stop();%0A
+%0A
         
 StopWatc
@@ -1058,136 +1058,55 @@
     
-StopWatch stopWatch2 = new StopWatch();%0A        stopWatch2.start();%0A        fibonacciService.compute(n);%0A        stopWatch2.stop
+long duration = stopWatch.getLastTaskTimeMillis
 ();%0A
@@ -1207,65 +1207,59 @@
 r/%3E 
-The first time, it took %7B2%7Dms %3Cbr/%3EThe second time, %7B3%7Dms
+It took %3Cfont color=%5C%22red%5C%22%3E%7B2%7D%3C/font%3Ems %3Cbr/%3E%3Cbr/%3E
 %22,%0A 
@@ -1320,95 +1320,208 @@
     
-stopWatch.getLastTaskTimeMillis(),%0A                stopWatch2.getLastTaskTimeMillis()))
+duration)%0A        + commentary(duration));%0A    %7D%0A%0A%0A%0A%0A%0A    private String commentary(long duration) %7B%0A        return duration %3E 1L ? %22A bit %3Ci%3Elong%3C/i%3E don't you think?%22 : %22Woaw that was %3Ci%3Efast%3C/i%3E !%22
 ;%0A  

change look of Endpoint