import { execute } from '../../../utils/db'
import { refreshServerTimer } from '../../../utils/server-scheduler'

export default defineEventHandler(async (event) => {
  const targetId = getRouterParam(event, 'id')
  
  if (!targetId) {
    throw createError({
      statusCode: 400,
      message: 'target_id is required'
    })
  }
  
  // 스케줄러에서 제거
  refreshServerTimer(Number(targetId))
  
  const changes = await execute(
    'DELETE FROM server_targets WHERE target_id = $1',
    [targetId]
  )
  
  return {
    success: true,
    changes
  }
})
