/**
 * Manual smoke test for the Awwwards crawler.
 * Runs one page of SOTD against the live site and prints extracted sites.
 * Not a unit test — calls the real Awwwards gallery.
 *
 * Run with:  bun run scripts/eye-ingest-crawl-test.ts
 */

import {
  discoverPageCount,
  fetchGalleryPage,
} from '../src/services/designHarness/eyeIngester/crawler.js'
import { DEFAULT_INGEST_CONFIG } from '../src/services/designHarness/eyeIngester/types.js'

async function main(): Promise<void> {
  const config = DEFAULT_INGEST_CONFIG

  for (const tier of ['SOTY', 'SOTM', 'SOTD'] as const) {
    process.stdout.write(`\n--- ${tier} ---\n`)
    const totalPages = await discoverPageCount(tier, config)
    process.stdout.write(`  pages available: ${totalPages}\n`)
    const sites = await fetchGalleryPage(tier, 1, config)
    process.stdout.write(`  page 1 extracted ${sites.length} sites\n`)

    for (const s of sites.slice(0, 3)) {
      process.stdout.write(`    [${s.tier}] ${s.title} — ${s.liveUrl}\n`)
      process.stdout.write(
        `      industry=${s.industryTags.join('|')}  tech=${s.techTags.join('|')}  style=${s.styleTags.slice(0, 4).join('|')}\n`,
      )
    }

    await new Promise((r) => setTimeout(r, config.requestDelayMs))
  }
}

main().catch((err: unknown) => {
  process.stderr.write(`CRAWL TEST FAILED: ${err instanceof Error ? err.message : String(err)}\n`)
  process.exit(1)
})
