
import { NextResponse } from "next/server";
import { scanAllLibraries, scanSelectedLibrary } from "@/lib/scanner";

export async function POST(request: Request) {
  try {
    const body = await request.json();
    const { libraryId } = body;

    if (libraryId) {
      // Scan specific library
      await scanSelectedLibrary(libraryId);
      return NextResponse.json({ message: `Library ${libraryId} scan complete` });
    } else {
      // Scan all libraries
      await scanAllLibraries();
      return NextResponse.json({ message: "All libraries scan complete" });
    }
  } catch (error: any) {
    return NextResponse.json({ error: error.message }, { status: 500 });
  }
}
