package router

import (
	"context"
	"testing"
	"time"
)

// TestDativePluralHourIsAnHour — "напомни к двум часам позвонить маме" reached
// the daemon with no time at all and she asked the open "Когда?", while "к трём"
// one word over read fine (V-609). The word that lost it was "часам", the dative
// plural of "час", which four separate hour sets in this package left out.
func TestDativePluralHourIsAnHour(t *testing.T) {
	const s = "напомни к двум часам позвонить маме"
	if !MentionsTime(s) {
		t.Errorf("MentionsTime(%q) = false; the sentence names two o'clock", s)
	}
	if !NamesAnHour(s) {
		t.Errorf("NamesAnHour(%q) = false; the sentence names two o'clock", s)
	}
	if got, want := SpellOutDigits(s), "напомни к 2 часам позвонить маме"; got != want {
		t.Errorf("SpellOutDigits(%q) = %q, want %q", s, got, want)
	}
	// The slot itself, which is what the daemon reads. It was empty, so
	// whenGapOf named the hour missing and she asked "Когда?".
	now := time.Date(2026, 8, 6, 3, 39, 0, 0, time.UTC)
	ex := Extractor{Time: StubDateTimeParser{}}
	got := ex.Extract(context.Background(), IntentReminder, s, now)
	if !got.HasTime {
		t.Fatalf("the hour was spoken, so the slot must be filled: %+v", got)
	}
	if h := got.Time.Hour(); h != 2 && h != 14 {
		t.Errorf("fire time = %s, want two o'clock in one half of the day or the other", got.Time.Format("15:04"))
	}
}

// TestHourUnitReachesEverySite — the four sets that read the hour noun now read
// one lexicon key, so a form added there is a form all four know. "часам" is the
// form that was missing from every one of them.
func TestHourUnitReachesEverySite(t *testing.T) {
	for _, w := range []string{"час", "часа", "часов", "часу", "часам"} {
		if !numeralContext[w] {
			t.Errorf("numeralContext is missing %q", w)
		}
		if !hourMarkers[w] {
			t.Errorf("hourMarkers is missing %q", w)
		}
		if !timeMarkers[w] {
			t.Errorf("timeMarkers is missing %q", w)
		}
		if _, ok := unitToDuration(2, w); !ok {
			t.Errorf("unitToDuration does not know %q", w)
		}
	}
}

// TestMinuteUnitHasTheSameForms — the same defect one noun over: "минутам" was
// missing everywhere "минут" and "минуты" were present.
func TestMinuteUnitHasTheSameForms(t *testing.T) {
	for _, w := range []string{"минут", "минуты", "минуту", "минутам"} {
		if !numeralContext[w] {
			t.Errorf("numeralContext is missing %q", w)
		}
		if !hourMarkers[w] {
			t.Errorf("hourMarkers is missing %q", w)
		}
		if !timeMarkers[w] {
			t.Errorf("timeMarkers is missing %q", w)
		}
		if _, ok := unitToDuration(20, w); !ok {
			t.Errorf("unitToDuration does not know %q", w)
		}
	}
}
