package infrastructure.interceptor;

import infrastructure.context.TraceIdContext;
import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientRequestFilter;
import jakarta.ws.rs.ext.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

@Provider
public class LoggingFilter implements ClientRequestFilter {
    private static final Logger LOG = LoggerFactory.getLogger(LoggingFilter.class);

    private final TraceIdContext traceIdContext;

    public LoggingFilter(TraceIdContext traceIdContext) {
        this.traceIdContext = traceIdContext;
    }

    @Override
    public void filter(ClientRequestContext requestContext) throws IOException {
        var requestId = traceIdContext.getTraceId();

        LOG.info("[{}] Peticion REST a: {} {}",
                requestId,
                requestContext.getMethod(),
                requestContext.getUri());
    }
}