import { scanMusicFolder } from '../../utils/fileScanner'

export default defineEventHandler(async (event) => {
  const runtimeConfig = useRuntimeConfig()
  const folderPath = runtimeConfig.NUXT_PATH_FILES

  try {
    // Test 1: Vérifier que le dossier existe
    const { access } = await import('node:fs/promises')
    await access(folderPath)

    // Test 2: Scanner le dossier
    const cards = await scanMusicFolder(folderPath)

    return {
      success: true,
      folderPath,
      cardsFound: cards.length,
      cards: cards.slice(0, 5), // Afficher seulement les 5 premiers
      sample: cards[0] // Un exemple complet
    }
  } catch (error: any) {
    return {
      success: false,
      error: error.message,
      folderPath
    }
  }
})
