import { NextResponse } from 'next/server';
import { query } from '@/lib/db';
import { getAdminSession } from '@/lib/auth';

export async function GET() {
  const session = await getAdminSession();
  if (!session) {
    return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
  }

  try {
    const profiles = await query(
      `SELECT user_email, wellness_goal, days_per_week, activity_level, updated_at FROM user_profiles`
    ) as any[];
    return NextResponse.json({ profiles });
  } catch (err: any) {
    console.error('[admin/profiles] GET error:', err?.message ?? err);
    return NextResponse.json({ error: 'Failed to load profiles.' }, { status: 500 });
  }
}
