package handlers

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

	"github.com/rede5/gohorsejobs/backend/internal/services"
)

func TestStorageHandler_GetUploadURL(t *testing.T) {
	t.Run("requires authentication context", func(t *testing.T) {
		// Create handler with nil credentials service (will fail)
		storageService := services.NewStorageService(nil)
		handler := NewStorageHandler(storageService)

		req := httptest.NewRequest("GET", "/api/v1/storage/upload-url?key=test.png&contentType=image/png", nil)
		w := httptest.NewRecorder()

		handler.GetUploadURL(w, req)

		// Should fail due to nil credentials service
		if w.Code == http.StatusOK {
			t.Log("Unexpected success with nil credentials")
		}
		// Main assertion: handler doesn't panic
	})

	t.Run("requires key parameter", func(t *testing.T) {
		storageService := services.NewStorageService(nil)
		handler := NewStorageHandler(storageService)

		// Missing key parameter
		req := httptest.NewRequest("GET", "/api/v1/storage/upload-url?contentType=image/png", nil)
		w := httptest.NewRecorder()

		handler.GetUploadURL(w, req)

		// Should return error for missing key
		if w.Code == http.StatusOK {
			t.Error("Expected error for missing key parameter")
		}
	})

	t.Run("requires contentType parameter", func(t *testing.T) {
		storageService := services.NewStorageService(nil)
		handler := NewStorageHandler(storageService)

		// Missing contentType parameter
		req := httptest.NewRequest("GET", "/api/v1/storage/upload-url?key=test.png", nil)
		w := httptest.NewRecorder()

		handler.GetUploadURL(w, req)

		// Should return error for missing contentType
		if w.Code == http.StatusOK {
			t.Error("Expected error for missing contentType parameter")
		}
	})
}
