import { NextResponse } from 'next/server'
import { auth } from '@/lib/auth'
import { getCreditStats } from '@/lib/services/credit'
import { headers } from 'next/headers'

export async function GET() {
  try {
    const session = await auth.api.getSession({
      headers: await headers()
    })
    
    if (!session?.user) {
      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
    }

    const stats = await getCreditStats(session.user.id)

    return NextResponse.json(stats)
  } catch (error) {
    console.error('Error fetching credit stats:', error)
    return NextResponse.json(
      { error: 'Internal server error' },
      { status: 500 }
    )
  }
}