import { NextResponse } from 'next/server'

export async function GET() {
  try {
    console.log('🔍 Testing Zeta Markets SDK imports...')

    // Test imports
    const zeta = await import('@zetamarkets/sdk')
    console.log('Zeta SDK exports:', Object.keys(zeta))

    // Test Solana imports
    const { Connection, Keypair } = await import('@solana/web3.js')
    const { Wallet } = await import('@coral-xyz/anchor')

    if (!process.env.SOLANA_PRIVATE_KEY) {
      return NextResponse.json({
        success: false,
        error: 'SOLANA_PRIVATE_KEY not configured',
        zetaExports: Object.keys(zeta),
        message: 'Zeta SDK imports working but wallet not configured'
      })
    }

    // Test wallet creation
    const privateKeyArray = JSON.parse(process.env.SOLANA_PRIVATE_KEY)
    const keypair = Keypair.fromSecretKey(new Uint8Array(privateKeyArray))
    const wallet = new Wallet(keypair)

    return NextResponse.json({
      success: true,
      message: 'Zeta Markets SDK imports successful',
      zetaExports: Object.keys(zeta),
      walletPublicKey: keypair.publicKey.toString(),
      timestamp: Date.now()
    })

  } catch (error) {
    console.error('❌ Zeta test error:', error)
    
    return NextResponse.json({
      success: false,
      error: error.message,
      stack: error.stack
    }, { status: 500 })
  }
}

export async function POST() {
  return NextResponse.json({
    message: 'Use GET method to test Zeta imports'
  }, { status: 405 })
}
