import { db } from './index.js'
import { decryptSecret } from './crypto.js'

export function loadSecrets(integrationId: number): Record<string, string> {
  const rows = db
    .prepare('SELECT key, value_encrypted FROM secrets WHERE integration_id = ?')
    .all(integrationId) as { key: string; value_encrypted: string }[]
  const out: Record<string, string> = {}
  for (const row of rows) out[row.key] = decryptSecret(row.value_encrypted)
  return out
}
