#!/usr/bin/env tsx
import { config as dotenvConfig } from 'dotenv'
dotenvConfig({ path: '.env' })

import { parseWebflowCSV } from './csvParser'
import { transformPosts } from './transformers'

async function main() {
  const data = await parseWebflowCSV('/Users/pukpuk/Dev/website-enchun-mgr/恩群數位行銷 - 行銷放大鏡集.csv')

  const failPost = data.posts.find((p: any) => p.title.includes('一點都不難'))
  const transformed = transformPosts([failPost])[0]

  console.log('=== TRANSFORMED POST DATA ===')
  console.log('title:', transformed.title)
  console.log('slug:', transformed.slug)
  console.log('publishedAt:', transformed.publishedAt)
  console.log('status:', transformed.status)
  console.log('excerpt:', transformed.excerpt?.substring(0, 100))
  console.log('content type:', typeof transformed.content)
  console.log('content length:', transformed.content?.length)

  // Parse and check content
  const contentParsed = JSON.parse(transformed.content)
  console.log('content.root exists:', contentParsed.root !== undefined)
  console.log('content.root.type:', contentParsed.root?.type)
}

main().catch(console.error)
