package main

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

	tasktracker "github.com/ankush/implementation-practice/level1_task_tracker"
	urlshortener "github.com/ankush/implementation-practice/level3_url_shortener"
	notification "github.com/ankush/implementation-practice/level4_notification_system"
)

func TestGatewayRoutes(t *testing.T) {
	// Initialize subsystems with test storage
	tmpDir := t.TempDir()
	dbPath := filepath.Join(tmpDir, "tasks.json")
	tm := tasktracker.NewTaskManager(dbPath)

	store := urlshortener.NewMemoryStore()
	hub := notification.NewHub()
	go hub.Run()

	app := &AppContainer{
		TaskManager: tm,
		URLStore:    store,
		Hub:         hub,
	}

	router := SetupGatewayRouter(app)

	// Verify routes compile and register correctly (even before custom handlers are finished)
	
	// Test GET /tasks routing
	req, _ := http.NewRequest("GET", "/tasks", nil)
	w := httptest.NewRecorder()
	router.ServeHTTP(w, req)
	if w.Code == http.StatusNotFound {
		t.Error("Expected GET /tasks route to be registered, got 404")
	}

	// Test GET /nonexistent_short_code
	req, _ = http.NewRequest("GET", "/abcde", nil)
	w = httptest.NewRecorder()
	router.ServeHTTP(w, req)
	if w.Code == http.StatusNotFound && w.Body.String() == "" {
		// Standard unresolved router paths usually return 404.
		// If our handler is hit, it will look up 'abcde' and return not found.
	}
}
