package placement

import (
	"strings"
	"testing"

	"haixun-backend/internal/library/websearch"
)

func TestBuildRelevanceQueryUsesBroadSiteSearch(t *testing.T) {
	q := BuildRelevanceQuery(websearch.ProviderBrave, "化療 無香 洗衣精 推薦")
	if !strings.HasPrefix(q, "site:threads.net ") {
		t.Fatalf("unexpected query %q", q)
	}
	if strings.Contains(q, `"`) {
		t.Fatalf("expected unquoted broad query, got %q", q)
	}
	if !strings.Contains(q, "推薦") {
		t.Fatalf("expected intent marker in query, got %q", q)
	}
}

func TestBuildRecencyQueryUsesShortCore(t *testing.T) {
	q := BuildRecencyQuery(websearch.ProviderBrave, "化療 無香 洗衣精 推薦 請問", 7)
	if !strings.Contains(q, "請問 after:") {
		t.Fatalf("expected recency date filter, got %q", q)
	}
	quoted := strings.Trim(q, `site:threads.net `)
	if strings.Contains(quoted, "推薦") {
		t.Fatalf("expected short quoted core without 推薦, got %q", q)
	}
}
