package net.paslavsky.msm.web

import net.paslavsky.msm.system.MSMWebUIDetector
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseBody
import kotlin.properties.Delegates
import net.paslavsky.msm.setting.SystemInfo

/**
 * Root controller
 *
 * @author Andrey Paslavsky
 * @version 1.0
 */
Controller
public class IndexController @Autowired constructor(
        private val msmWebUIDetector: MSMWebUIDetector,
        private val systemInfoHolder: SystemInfo) {
    RequestMapping("/")
    public fun index(): String = if (msmWebUIDetector.isWebUIIncluded())
        msmWebUIDetector.redirectToTheWebUI()
    else
        "redirect:/info"

    ResponseBody
    RequestMapping("/info")
    public fun info(): Map<String, String> = systemInfoHolder.systemInformation
}
