package com.style24.front.support.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import lombok.extern.slf4j.Slf4j;

/**
 * Return URL Interceptor
 * 
 * @author gagamel
 * @since 2020. 9. 11
 */
@Component
@Slf4j
public class TsfReturnUrlInterceptor extends HandlerInterceptorAdapter {

//	@Value("${has-ssl}")
//	private String hasSsl;

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//		log.info("request.isSecure(): [{}]", request.isSecure());
//		log.info("request.getServerName(): [{}]", request.getServerName());
//		log.info("request.getRequestURI(): [{}]", request.getRequestURI());
//		log.info("request.getRequestURL(): [{}]", request.getRequestURL());
//		log.info("request.getQueryString(): [{}]", request.getQueryString());
//
//		String queryString = GagaStringUtil.convertParameterToQueryString(request.getParameterMap());
//		if (StringUtils.isNotBlank(queryString))
//			queryString = "?" + queryString;
//		log.info("queryString: [{}]", queryString);
//
//		String returnUrl = request.getRequestURL() + queryString;
//		log.info("returnUrl: [{}]", returnUrl);
//
//		// SSL Server
//		boolean isSslServer = Boolean.parseBoolean(hasSsl);
//		log.debug("isSslServer: [{}]", isSslServer);
//
//		if (isSslServer) {
//			GagaCookieUtil.setSecureCookie(response, FoConstants.CK_PREFIX + "_return_url", returnUrl, -1);
//		} else {
//			GagaCookieUtil.setCookie(response, FoConstants.CK_PREFIX + "_return_url", returnUrl, -1);
//		}

		return super.preHandle(request, response, handler);
	}

	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
		ModelAndView modelAndView) throws Exception {
		// Do nothing
	}

}
