import { db } from '../db/db_index'
import { keyValStore, productInfo } from '../db/schema'

/**
 * Health check - test database connectivity
 * Tries to select from keyValStore first, falls back to productInfo
 */
export async function healthCheck(): Promise<{ status: string }> {
  try {
    // Try keyValStore first (smaller table)
    await db.select({ key: keyValStore.key }).from(keyValStore).limit(1)
    return { status: 'ok' }
  } catch {
    // Fallback to productInfo
    await db.select({ name: productInfo.name }).from(productInfo).limit(1)
    return { status: 'ok' }
  }
}
