package demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/kalkulator")
public class KalkulatorController {
    @Autowired
    private LogikaKalkulatora logika;

    @GetMapping
    public String kalkulatorGet() {
        return "kalkulator.html";
    }

    @PostMapping
    public String kalkulatorPost(Model model, Integer arg1, Integer arg2, String operacja) {
        int wynik = logika.oblicz(arg1, arg2, operacja);
        model.addAttribute("wynik", wynik);
        return "kalkulator.html";
    }

    @GetMapping("/historia")
    public String wyswietlHistorie(Model model) {
        model.addAttribute("historia", logika.getHistoriaDzialan());
        return "historia.html";
    }

}
