package loader

import (
	"os"
	"path/filepath"
	"testing"
)

func TestCSVLoaderRejectsNonHTTPSchemes(t *testing.T) {
	// Create temp CSV
	tmpDir := t.TempDir()
	csvPath := filepath.Join(tmpDir, "test.csv")
	
	content := `name,external_link,status
Valid HTTP,https://example.com,Up
Valid plain,example.org,Up
FTP scheme,ftp://badscheme.com,Up
File scheme,file:///etc/passwd,Up
mailto,mailto:test@example.com,Up
Down site,https://down.com,Down`
	
	if err := os.WriteFile(csvPath, []byte(content), 0644); err != nil {
		t.Fatal(err)
	}
	
	l := NewCSVLoader(DefaultCSVConfig())
	result, err := l.Load(csvPath)
	if err != nil {
		t.Fatal(err)
	}
	
	// Expected:
	// - "Valid HTTP" -> valid target (example.com)
	// - "Valid plain" -> valid target (example.org) - https:// prepended
	// - "FTP scheme" -> InvalidURLs (non-HTTP scheme)
	// - "File scheme" -> InvalidURLs (non-HTTP scheme)
	// - "mailto" -> InvalidURLs (non-HTTP scheme)
	// - "Down site" -> Filtered (status=Down)
	
	if result.TotalRows != 6 {
		t.Errorf("TotalRows: got %d, want 6", result.TotalRows)
	}
	if len(result.Targets) != 2 {
		t.Errorf("Targets: got %d, want 2 (example.com, example.org)", len(result.Targets))
	}
	if result.InvalidURLs != 3 {
		t.Errorf("InvalidURLs: got %d, want 3 (ftp, file, mailto)", result.InvalidURLs)
	}
	if result.Filtered != 1 {
		t.Errorf("Filtered: got %d, want 1 (Down)", result.Filtered)
	}
	
	t.Logf("TotalRows: %d", result.TotalRows)
	t.Logf("Targets: %v", result.Targets)
	t.Logf("InvalidURLs: %d", result.InvalidURLs)
	t.Logf("Filtered: %d", result.Filtered)
}
