import { NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { prisma } from '@/lib/db'

export async function GET() {
  const user = await getSession()
  
  if (!user) {
    return NextResponse.json({ user: null, tenant: null })
  }

  // Enrich with tenant subscription info for non-server-admins
  let tenant: any = null
  if (user.tenantId) {
    tenant = await (prisma as any).tenant.findUnique({
      where: { id: user.tenantId },
      select: {
        id: true,
        name: true,
        slug: true,
        plan: true,
        subscriptionStatus: true,
        trialEndsAt: true,
        subscriptionEndsAt: true,
        maxUsers: true,
        maxProjects: true,
        logoUrl: true,
      },
    })
  }

  return NextResponse.json({ user, tenant })
}
