package router

import (
	"context"
	"testing"
)

func feedRouter(t *testing.T) *Router {
	t.Helper()
	r := newTestRouter(t, 0.0)
	r.grammars = append(r.grammars, SystemTimeDateGrammars()...)
	r.grammars = append(r.grammars, AgendaQueryGrammars()...)
	r.grammars = append(r.grammars, FeedQueryGrammar())
	return r
}

// The documented utterance of task 258 step 1 routed system and answered
// "пока не умею отвечать на этот вопрос.", while the same question worded with
// "новостях" worked (Vikunja #474).
func TestFeedQuestionsRouteToQuery(t *testing.T) {
	r := feedRouter(t)
	for _, u := range []string{
		"что нового в лентах?",
		"что в лентах?",
		"расскажи что в новостных лентах",
		"покажи ленту",
	} {
		d, err := r.Route(context.Background(), u, refNow())
		if err != nil {
			t.Fatalf("route(%q): %v", u, err)
		}
		if d.Intent != IntentQuery {
			t.Errorf("route(%q) = %s, want query", u, d.Intent)
		}
	}
}

// The greeting and the statement keep their intents. "что нового?" is the most
// common opener in the language, and a rule that claimed it would answer hello
// with a configuration status.
func TestFeedGrammarLeavesTheGreetingAlone(t *testing.T) {
	r := feedRouter(t)
	for _, u := range []string{
		"что нового?",
		"у меня новая лента в инстаграме",
	} {
		d, err := r.Route(context.Background(), u, refNow())
		if err != nil {
			t.Fatalf("route(%q): %v", u, err)
		}
		if d.Stage == 0 {
			t.Errorf("route(%q) was claimed at stage 0 as %s", u, d.Intent)
		}
	}
}
