package middleware

import (
	"time"

	"counter/internal/infrastructure/metrics"

	"github.com/gin-gonic/gin"
)

// MetricsMiddleware creates a Gin middleware for HTTP metrics
func MetricsMiddleware(metricsService metrics.MetricsService) gin.HandlerFunc {
	return func(c *gin.Context) {
		start := time.Now()

		c.Next()

		duration := time.Since(start)
		metricsService.RecordHTTPRequest(c.Request.Method, c.FullPath(), c.Writer.Status(), duration)
	}
}
