import prisma from '../lib/prisma'

async function debugConfig() {
  console.log('=== System Configuration Debug ===\n')

  const configs = await prisma.systemConfig.findMany()

  console.log(`Total configs in DB: ${configs.length}\n`)

  // Group by category
  const aiConfigs = configs.filter(c => c.key.startsWith('AI_'))
  const ollamaConfigs = configs.filter(c => c.key.includes('OLLAMA'))
  const openaiConfigs = configs.filter(c => c.key.includes('OPENAI'))

  console.log('=== AI Provider Configs ===')
  aiConfigs.forEach(c => {
    console.log(`${c.key}: "${c.value}"`)
  })

  console.log('\n=== Ollama Configs ===')
  ollamaConfigs.forEach(c => {
    console.log(`${c.key}: "${c.value}"`)
  })

  console.log('\n=== OpenAI Configs ===')
  openaiConfigs.forEach(c => {
    console.log(`${c.key}: "${c.value}"`)
  })

  console.log('\n=== All Configs ===')
  configs.forEach(c => {
    console.log(`${c.key}: "${c.value}"`)
  })
}

debugConfig()
  .then(() => process.exit(0))
  .catch((err) => {
    console.error(err)
    process.exit(1)
  })
