#!/usr/bin/env tsx
/**
 * Test CSV Parser (No MongoDB required)
 */

import { parseWebflowCSV } from './csvParser'
import { Logger } from './utils'

const logger = new Logger(true)

async function main() {
  const csvPath = process.argv[2] || '../../恩群數位行銷 - 行銷放大鏡集 - 61f24aa108528b279f942ca9.csv'

  logger.header('🧪 Testing CSV Parser')
  logger.info(`File: ${csvPath}`)

  try {
    const data = await parseWebflowCSV(csvPath)

    logger.success(`✓ CSV parsed successfully!`)
    logger.info(`Posts: ${data.posts?.length || 0}`)
    logger.info(`Categories: ${data.categories?.length || 0}`)
    logger.info(`Portfolio: ${data.portfolio?.length || 0}`)

    if (data.categories && data.categories.length > 0) {
      logger.info('\n📋 Categories found:')
      for (const cat of data.categories) {
        logger.info(`  - ${cat.name} (${cat.slug}) - ${cat.colorHex}`)
      }
    }

    if (data.posts && data.posts.length > 0) {
      logger.info('\n📝 First 5 posts:')
      for (const post of data.posts.slice(0, 5)) {
        logger.info(`  - [${post.postCategory || 'uncategorized'}] ${post.title}`)
        logger.debug(`    Slug: ${post.slug}`)
        logger.debug(`    Date: ${post.publishedDate}`)
      }
    }

  } catch (error) {
    logger.error(`Error: ${error}`)
  }
}

main()
