package handlers

import (
	"net/http"

	"warpbox.dev/backend/libs/middleware"
)

func requestLogAttrs(r *http.Request) []any {
	attrs := []any{
		"ip", uploadClientIP(r),
		"method", r.Method,
		"path", r.URL.Path,
	}
	if requestID := middleware.RequestIDFromContext(r.Context()); requestID != "" {
		attrs = append(attrs, "request_id", requestID)
	}
	if userAgent := r.UserAgent(); userAgent != "" {
		attrs = append(attrs, "user_agent", userAgent)
	}
	return attrs
}

func withRequestLogAttrs(r *http.Request, attrs ...any) []any {
	out := make([]any, 0, len(attrs)+8)
	out = append(out, attrs...)
	out = append(out, requestLogAttrs(r)...)
	return out
}
