package naming

import "testing"

func TestFallbackName(t *testing.T) {
	tests := []struct {
		name    string
		context string
		hint    string
		want    string
	}{
		{
			name:    "release title with tech specs",
			context: "Дюна: Часть вторая / Dune: Part Two [2024, фантастика, WEB-DL 2160p]\nDub + MVO",
			want:    "Дюна: Часть вторая / Dune: Part Two",
		},
		{
			name:    "skips url and command lines",
			context: "magnet:?xt=urn:btih:abc\nhttps://example.com/x\n/help\nБрат [1997]",
			want:    "Брат",
		},
		{
			name:    "empty context falls back to magnet dn hint",
			context: "",
			hint:    "rutracker-topic-6514485",
			want:    "rutracker-topic-6514485",
		},
		{
			name:    "useless context and no hint yields empty",
			context: "https://example.com/x\n/help",
			hint:    "",
			want:    "",
		},
		{
			name:    "strips markdown url tail",
			context: "Сёгун (https://hashurl.ru/abc)",
			want:    "Сёгун",
		},
		{
			name:    "strips tech specs in round brackets with year",
			context: "Дюна (2024, фантастика, WEB-DL 2160p)",
			want:    "Дюна",
		},
		{
			name:    "keeps non-spec parenthesis (director)",
			context: "Брат (Алексей Балабанов) [1997, криминал]",
			want:    "Брат (Алексей Балабанов)",
		},
		{
			name:    "inline url does not drop the title line",
			context: "Дюна 2024 подробнее http://tracker/x",
			want:    "Дюна 2024 подробнее http://tracker/x",
		},
	}
	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			if got := fallbackName(tc.context, tc.hint); got != tc.want {
				t.Errorf("fallbackName() = %q, want %q", got, tc.want)
			}
		})
	}
}
