package placement

import (
	"strings"
	"time"
)

type QueryDimension string

const (
	QueryRelevance QueryDimension = "relevance"
	QueryRecency   QueryDimension = "recency"
)

type TagQuery struct {
	Tag             string
	Query           string
	Dimension       QueryDimension
	GraphNodeID     string
	ProductFitScore int
	RecencyDays     int // 0 = no after filter; 7 or 30 for recency track
}

func BuildRelevanceQuery(tag string) string {
	tag = strings.TrimSpace(tag)
	if tag == "" {
		return ""
	}
	return `site:threads.net "` + tag + `"`
}

func BuildRecencyQuery(tag string, maxAgeDays int) string {
	tag = strings.TrimSpace(tag)
	if tag == "" {
		return ""
	}
	after := FormatAfterDate(maxAgeDays, timeNow())
	return `site:threads.net "` + tag + `" 請問 after:` + after
}

var timeNow = func() time.Time { return time.Now() }

// SetTimeNowForTest overrides time source in tests.
func SetTimeNowForTest(fn func() time.Time) {
	timeNow = fn
}
