package com.tashow.cloud.app.interceptor;

import cn.hutool.core.util.IdUtil;
import com.tashow.cloud.app.mq.message.BuriedMessages;
import com.tashow.cloud.app.mq.producer.buriedPoint.BuriedPointProducer;
import com.tashow.cloud.common.util.json.JsonUtils;
import com.tashow.cloud.common.util.servlet.ServletUtils;
import com.tashow.cloud.common.util.spring.SpringUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 后端静默埋点拦截器
 * 用于收集API请求信息并异步发送到消息队列
 */
@Slf4j
@RequiredArgsConstructor
public class BuriedPointInterceptor implements HandlerInterceptor {

    private final BuriedPointProducer buriedPointProducer;



    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        if (!(handler instanceof HandlerMethod handlerMethod)) {
            return true;
        }
            BuriedMessages message = new BuriedMessages(
                request,
                handlerMethod
            );
            buriedPointProducer.asyncSendMessage(message);
        return true;
    }


} 