package persona

import (
	"strings"
	"testing"
	"time"
)

var ref = time.Date(2026, 7, 31, 14, 5, 0, 0, time.UTC)

// The block must be correct with an empty config: the address form and the
// gender rules are hard constraints, not preferences.
func TestBlockWorksWithZeroConfig(t *testing.T) {
	b := Facts{}.Block(ref)
	for _, want := range []string{"женском роде", "ОБРАЩЕНИЕ", "\"ты\"", "31 июля 2026", "пятница", "14:05"} {
		if !strings.Contains(b, want) {
			t.Errorf("block missing %q:\n%s", want, b)
		}
	}
}

func TestBlockAddsOptionalFacts(t *testing.T) {
	b := Facts{OwnerName: "Ками", City: "Москва", Static: "Будь краткой."}.Block(ref)
	for _, want := range []string{"Ками", "Москва", "Будь краткой."} {
		if !strings.Contains(b, want) {
			t.Errorf("block missing %q:\n%s", want, b)
		}
	}
}

// The time changes between turns, so two renders must differ.
func TestBlockRendersTimePerTurn(t *testing.T) {
	a := Facts{}.Block(ref)
	c := Facts{}.Block(ref.Add(time.Hour))
	if a == c {
		t.Errorf("block did not change with the clock:\n%s", a)
	}
}

// She may only offer what this deployment actually has.
func TestCapabilitiesAreConfigGated(t *testing.T) {
	bare := Facts{}.Block(ref)
	for _, want := range []string{"напоминания", "заметки", "календарь"} {
		if !strings.Contains(bare, want) {
			t.Errorf("block missing always-on capability %q:\n%s", want, bare)
		}
	}
	for _, unwanted := range []string{"погоду", "телеграм", "команды"} {
		if strings.Contains(bare, unwanted) {
			t.Errorf("block offers unconfigured %q:\n%s", unwanted, bare)
		}
	}

	full := Facts{Weather: true, Telegram: true, Tools: true}.Block(ref)
	for _, want := range []string{"погоду", "телеграм", "команды"} {
		if !strings.Contains(full, want) {
			t.Errorf("block missing configured capability %q:\n%s", want, full)
		}
	}
}

func TestPrependNilIsSafe(t *testing.T) {
	if got := Prepend(nil, "PROMPT"); got != "PROMPT" {
		t.Errorf("Prepend(nil) = %q", got)
	}
	if got := Prepend(func() string { return "  " }, "PROMPT"); got != "PROMPT" {
		t.Errorf("Prepend(blank) = %q", got)
	}
	if got := Prepend(func() string { return "CTX" }, "PROMPT"); got != "CTX\n\nPROMPT" {
		t.Errorf("Prepend = %q", got)
	}
}
