package llm

import (
	"context"
	"time"
)

// CollocationInterval is the minimum gap between collocation passes for one
// document. Like the voice pass it runs on an explicit user action ("Make it
// sound natural") rather than a typing cadence, so this floor only guards the
// inference endpoint against the button being mashed.
const CollocationInterval = 25 * time.Second

// RunCollocation sends the WHOLE document for a collocation pass — gentle
// "natives usually say…" hints on non-native word pairings — and parses the JSON
// result with the checkpoint's tolerant parser. It is deliberately NOT
// TruncateDoc'd: like the voice pass it reads the whole document so the hints
// reflect the full piece. Each flag carries a native replacement to apply.
//
// The tone argument is accepted for a uniform pass signature and passed through
// to the prompt so a hint can prefer a register-appropriate pairing.
func RunCollocation(ctx context.Context, client LLMClient, contentText, tone string) ([]RawSuggestion, error) {
	raw, err := client.Complete(ctx, CompletionRequest{
		Messages:          CollocationMessages(contentText, tone),
		MaxTokens:         2048,
		Temperature:       0.3,
		RepetitionPenalty: 1.15,
		TopP:              0.9,
		Stop:              []string{"```", "\n\n\n\n"},
	})
	if err != nil {
		return nil, err
	}
	return ParseCheckpoint(raw)
}
