import { NextRequest, NextResponse } from 'next/server';
import { previewReset } from '@/features/setup/server/reset.service';
import { AuthError, requireSystemRole } from '@/lib/auth/session';

export async function POST(request: NextRequest) {
  try {
    await requireSystemRole('super_admin');
    const body = await request.json();
    return NextResponse.json(await previewReset(body));
  } catch (error) {
    if (error instanceof AuthError) {
      return NextResponse.json({ message: error.message }, { status: error.status });
    }

    return NextResponse.json({ message: 'Unable to preview setup reset' }, { status: 500 });
  }
}
