package handlers

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/gin-gonic/gin"
	"github.com/stretchr/testify/assert"
)

func TestPrometheusMetrics_Success(t *testing.T) {
	// Setup
	gin.SetMode(gin.TestMode)
	router := gin.New()

	router.GET("/metrics", PrometheusMetrics())

	// Execute
	req, _ := http.NewRequest("GET", "/metrics", nil)
	w := httptest.NewRecorder()
	router.ServeHTTP(w, req)

	// Assert - Prometheus handler should return 200 OK
	assert.Equal(t, http.StatusOK, w.Code)
	// Prometheus metrics should be in the response body
	assert.Contains(t, w.Body.String(), "# HELP")
}

func TestPrometheusMetrics_WithQueryParams(t *testing.T) {
	// Setup
	gin.SetMode(gin.TestMode)
	router := gin.New()

	router.GET("/metrics", PrometheusMetrics())

	// Execute - With query params
	req, _ := http.NewRequest("GET", "/metrics?format=prometheus", nil)
	w := httptest.NewRecorder()
	router.ServeHTTP(w, req)

	// Assert
	assert.Equal(t, http.StatusOK, w.Code)
}
