package say

import (
	"math/rand"
	"strings"
	"testing"
)

// The file has to load, and every key the code names has to be in it.
func TestSummariesLoad(t *testing.T) {
	s, err := LoadSummaries(rand.NewSource(1))
	if err != nil {
		t.Fatalf("load: %v", err)
	}
	for _, key := range summaryKeys {
		if got := s.Say(key, nil); got == "" {
			t.Errorf("%s says nothing", key)
		}
	}
}

// A nil *Summaries is the unloadable-file case, and it must still speak. The
// habit sentences are the ones that matter here: falling back must not turn
// "I have not seen enough" into silence.
func TestNilSummariesAnswerFromTheFloor(t *testing.T) {
	var s *Summaries
	if got, want := s.Say(HabitOverallNone, nil), summaryFloor[HabitOverallNone]; got != want {
		t.Errorf("got %q, want %q", got, want)
	}
	if got := s.Say(PlanDay, map[string]string{"date": "03.08.2026", "items": "x"}); !strings.Contains(got, "03.08.2026") {
		t.Errorf("the floor dropped the date: %q", got)
	}
}

// The empty cases claim she has not seen enough, never that he has no habits.
// Every variant has to hold that line, since the picker treats them as equals.
func TestHabitGapsSaySheHasNotSeenEnough(t *testing.T) {
	s, err := LoadSummaries(rand.NewSource(1))
	if err != nil {
		t.Fatalf("load: %v", err)
	}
	for _, key := range []string{HabitWeekdayNone, HabitWeekendNone, HabitOverallNone} {
		for _, v := range s.d.file.Entries[key].Variants {
			if !strings.Contains(v, "пока") && !strings.Contains(v, "ещё") {
				t.Errorf("%s variant %q reads as a fact about him, not as a gap in her records", key, v)
			}
		}
	}
}

// One variant means fixed, in this file and in the four in internal/phraser.
// Nothing breaks on the flag being absent, but parallel entries disagreeing
// about it is how the file stops telling a reader which wording is load-bearing.
func TestEverySingleVariantEntryIsFixed(t *testing.T) {
	s, err := LoadSummaries(rand.NewSource(1))
	if err != nil {
		t.Fatalf("load: %v", err)
	}
	if got := s.d.UnfixedSingles(); len(got) > 0 {
		t.Errorf("single-variant entries not marked fixed: %v", got)
	}
}
