package com.qmth.sop.server.interceptor;

import com.qmth.boot.api.interceptor.ExtendInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;

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

@Component
public class AuthInterceptor extends ExtendInterceptor {
    private final static Logger log = LoggerFactory.getLogger(AuthInterceptor.class);

    @Value("${com.qmth.api.metrics-endpoint}")
    String endpoint;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("preHandle is come in");
//        if (request.getServletPath().contains(endpoint)) {
        return true;
//        } else {
//            return AuthUtil.adminAuthInterceptor(request, response, handler);
//        }
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
        log.info("postHandle is come in");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
        log.info("afterCompletion is come in");
    }

    @Override
    public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("afterConcurrentHandlingStarted is come in");
    }
}
