import { fetchRandomVerse } from '../src/lib/server/bible-api';
import { generateShareText } from '../src/lib/utils/share';
import { bibleBooks } from '../src/lib/types/bible';

const NUM_VERSES = 10;

for (let i = 0; i < NUM_VERSES; i++) {
	const verse = await fetchRandomVerse();

	// Build a fake "solved in N guesses" scenario with some wrong guesses first
	const correctBook = bibleBooks.find((b) => b.id === verse.bookId)!;
	const wrongBook = bibleBooks.find((b) => b.id !== verse.bookId)!;
	const guessCount = Math.floor(Math.random() * 5) + 1;
	const guesses = [
		...Array(guessCount - 1).fill(null).map(() => ({
			book: wrongBook,
			testamentMatch: wrongBook.testament === correctBook.testament,
			sectionMatch: wrongBook.section === correctBook.section,
			adjacent: Math.abs(wrongBook.order - correctBook.order) === 1,
		})),
		{ book: correctBook, testamentMatch: true, sectionMatch: true, adjacent: false },
	];

	const fakeStreak = Math.random() > 0.5 ? Math.floor(Math.random() * 14) + 2 : 0;

	const shareText = generateShareText({
		guesses,
		correctBookId: verse.bookId,
		dailyVerseDate: new Date().toISOString().slice(0, 10),
		chapterCorrect: guessCount === 1 && Math.random() > 0.5,
		isLoggedIn: Math.random() > 0.5,
		streak: fakeStreak > 0 ? fakeStreak : undefined,
		origin: 'https://bibdle.com',
		verseText: verse.verseText,
	});

	console.log(`\n── Verse ${i + 1}: ${verse.reference} ──`);
	console.log(`RAW: ${verse.verseText}`);
	console.log('─'.repeat(40));
	console.log(shareText);
}
