import { syncCardsWithDatabase } from '../../services/cardSync.service'

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

  try {
    const result = await syncCardsWithDatabase(folderPath)

    return {
      success: true,
      ...result
    }
  } catch (error: any) {
    return {
      success: false,
      error: error.message,
      stack: error.stack
    }
  }
})
