package game

import (
	"context"
	"testing"

	"github.com/google/uuid"
)

// TestSeatNamesUsesSnapshot checks seatNames returns each seat's stored display-name
// snapshot directly, without consulting the account store (svc.accounts is nil here, so
// any lookup would be skipped or panic).
func TestSeatNamesUsesSnapshot(t *testing.T) {
	svc := &Service{}
	g := Game{
		Players: 2,
		Seats: []Seat{
			{Seat: 0, AccountID: uuid.New(), DisplayName: "Аня2007"},
			{Seat: 1, AccountID: uuid.New(), DisplayName: "DarkWolf"},
		},
	}
	got := svc.seatNames(context.Background(), g)
	want := []string{"Аня2007", "DarkWolf"}
	if len(got) != len(want) || got[0] != want[0] || got[1] != want[1] {
		t.Fatalf("seatNames = %v, want %v", got, want)
	}
}

// TestSeatDisplayNameFallbackEmpty checks the resolver yields "" — rather than panicking
// — for a seat with no snapshot when no account store is available (the empty open seat
// and pre-snapshot legacy-row paths).
func TestSeatDisplayNameFallbackEmpty(t *testing.T) {
	svc := &Service{}
	if got := svc.seatDisplayName(context.Background(), Seat{Seat: 0, AccountID: uuid.New()}); got != "" {
		t.Errorf("seatDisplayName with no snapshot and no store = %q, want empty", got)
	}
	if got := svc.seatDisplayName(context.Background(), Seat{Seat: 1, AccountID: uuid.Nil}); got != "" {
		t.Errorf("empty-seat name = %q, want empty", got)
	}
}
