package com.master.demo.msdemo.resources;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/fib")
public class FibonacciResource {

    private static final Logger LOGGER = LoggerFactory.getLogger(FibonacciResource.class);

    private int count=0;
    private long helperFibo(int n){
        if (n <= 1) {
            return n;
        }
        return helperFibo(n - 1) + helperFibo(n - 2);
    }
    @RequestMapping("/{n}")
    public String fibonacci(@PathVariable("n") int n) {
        count++;
        LOGGER.info(String.format("request count %s", count));
        return  String.valueOf(helperFibo(n));
    }
}
