
import { NextRequest, NextResponse } from 'next/server';
import db from '@/db';

export async function DELETE(request: NextRequest, { params: paramsPromise }: { params: Promise<{ id: string }> }) {
  const params = await paramsPromise;
  const id = parseInt(params.id, 10);
  if (isNaN(id)) {
    return NextResponse.json({ error: 'Invalid ID' }, { status: 400 });
  }

  try {
    const info = db.prepare('DELETE FROM libraries WHERE id = ?').run(id);
    if (info.changes === 0) {
      return NextResponse.json({ error: 'Library not found' }, { status: 404 });
    }
    return NextResponse.json({ message: 'Library deleted' });
  } catch (error: any) {
    return NextResponse.json({ error: error.message }, { status: 500 });
  }
}
