import { shouldAutoStartScheduler } from '../utils/db'
import { privnetScheduler } from '../utils/privnet-scheduler'

export default defineNitroPlugin(async (nitroApp) => {
  console.log('[Plugin] privnet-init starting...')
  
  // 스케줄러 자동 시작 (환경에 따라)
  if (shouldAutoStartScheduler()) {
    privnetScheduler.start()
    console.log('[Plugin] privnet scheduler auto-started (production mode)')
  } else {
    console.log('[Plugin] privnet scheduler NOT started (development mode)')
  }
  
  // 서버 종료 시 클린업
  nitroApp.hooks.hook('close', () => {
    console.log('[Plugin] Shutting down privnet scheduler...')
    privnetScheduler.stop()
  })
  
  console.log('[Plugin] privnet-init completed')
})
