// API: GET /api/fitness/reports — Consolidated reports data for the user
import { NextRequest, NextResponse } from 'next/server';
import { getReportsData } from '@/lib/workout-planner/db';

export async function GET(request: NextRequest) {
  try {
    const userId = request.nextUrl.searchParams.get('userId');
    if (!userId) {
      return NextResponse.json({ error: 'userId is required' }, { status: 400 });
    }

    const data = await getReportsData(userId);
    return NextResponse.json(data);
  } catch (error: any) {
    console.error('Failed to fetch reports data:', error);
    return NextResponse.json(
      { error: 'Failed to fetch reports data', details: error.message },
      { status: 500 }
    );
  }
}
