package com.lemon.lifecenter.common;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mobile.device.Device;
import org.springframework.mobile.device.DeviceUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Component
public class LifeCenterInterCeptor extends HandlerInterceptorAdapter {
    @Autowired
    private LifeCenterConfigVO config;
    
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        System.out.println("--------------------- InterCeptor Start --------------------- ");

        String url = request.getRequestURI().toString();
        String port = String.valueOf(request.getLocalPort());
        Device device = DeviceUtils.getCurrentDevice(request);

        logger.info("IP : " + LifeCenterFunction.getRemoteAddr(request) + " URL : " + url + " Port : " + port
                + " Device : " + device);
        
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
            ModelAndView modelAndView) {
        logger.info("Method Executed Time : postHandle");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
            Exception ex) {
        logger.info("Method Completed Time : afterCompletion");
        System.out.println("--------------------- InterCeptor End ---------------------");
    }
}
