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

export async function DELETE(request: NextRequest) {
  try {
    const id = request.url.split('/').filter(Boolean).pop();

    if (!id) {
      return NextResponse.json(
        { success: false, error: 'Bookmark ID is required' },
        { status: 400 }
      );
    }

    const bookmark = await db.bookmark.findUnique({ where: { id } });

    if (!bookmark) {
      return NextResponse.json(
        { success: false, error: 'Bookmark not found' },
        { status: 404 }
      );
    }

    await db.bookmark.delete({ where: { id } });

    return NextResponse.json(
      { success: true, message: 'Bookmark deleted successfully' },
      { status: 200 }
    );
  } catch (error) {
    console.error('Delete bookmark error:', error);
    return NextResponse.json(
      { success: false, error: 'Internal server error' },
      { status: 500 }
    );
  }
}
