package main

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

	"github.com/FernandoVideira/LK_API_Temp/internal/auth"
	"github.com/FernandoVideira/LK_API_Temp/internal/ratelimiter"
	"github.com/FernandoVideira/LK_API_Temp/internal/store"
	"github.com/FernandoVideira/LK_API_Temp/internal/store/cache"
	"go.uber.org/zap"
)

func newTestApi(t *testing.T, cfg config) *api {
	t.Helper()

	logger := zap.NewNop().Sugar()
	mockStore := store.NewMockStorage()
	mockCache := cache.NewMockCache()
	testAuth := &auth.TestAuthenticator{}
	rateLimiter := ratelimiter.NewFixedWindowLimiter(
		cfg.rateLimiter.RequestsPerTimeFrame,
		cfg.rateLimiter.TimeFrame,
	)

	return &api{
		logger:        logger,
		store:         mockStore,
		cacheStore:    mockCache,
		authenticator: testAuth,
		config:        cfg,
		rateLimiter:   rateLimiter,
	}
}

func executeRequest(req *http.Request, mux http.Handler) *httptest.ResponseRecorder {
	rr := httptest.NewRecorder()
	mux.ServeHTTP(rr, req)
	return rr
}
