package com.tsiwebserver.controller;

import com.tsiwebserver.VO.UserVO;
import com.tsiwebserver.security.TSIEncoder;
import com.tsiwebserver.service.impl.LoginServiceImpl;
import io.micrometer.core.instrument.util.TimeUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

@Controller
@Slf4j
public class TsiWebServerController {

	private final Integer processId = 90010;
	private final String bootingTime;

	public TsiWebServerController() {
		this.bootingTime = now();
	}

	private String now() {
		Date today = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(today);
	}

	@GetMapping("/info")
	@ResponseBody
	public String info() {
		String sep = System.lineSeparator();
		String heading = "---------------------------------------------------------";

		StringBuilder sb = new StringBuilder();
		sb.append(heading).append(sep);
		sb.append("UTIC Wireless Web Management Server(Dashboard)").append(sep);
		sb.append(heading).append(sep);
		sb.append(String.format("Process Id: %s, %s, %s", this.processId, this.bootingTime, now())).append(sep);
		sb.append(heading).append(sep);
		sb.append("OK").append(sep);
		return sb.toString();
	}

}
