package com.altimetrik.ee.demo.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import com.altimetrik.ee.demo.service.FundTransferService;

@Controller
public class FundTransferController {
    
    @Value("${k8s.db.env}")
	private String deploymentEnv;

	@Value("${spring.h2.console.path}")    
    private String appName;

	@Autowired
	@Qualifier("FundTransferServiceImpl")
	private FundTransferService fundTransferService;
	
	@GetMapping(path="/index")
	public String home(Map<String, Object> model) {
		model.put("message", fundTransferService.home());
		return "index";
	}
	
	@GetMapping(path="/fundtransfer")
	public String fundtransfer(Map<String, Object> model) {
	    if (deploymentEnv != null && !deploymentEnv.isEmpty())
	        model.put("appName", appName);
		return "fundtransfer";
	}
	
	@PostMapping(path="/status")
	public String status(HttpServletRequest request, Map<String, Object> model) {
		String toAccount = request.getParameter("toAcc");
		model.put("message", fundTransferService.status(toAccount));
		return "status";
	}
}