import { createFileRoute } from "@tanstack/react-router";
import { scanExternalProviders } from "../../proxy/providerImporters";

export const Route = createFileRoute("/api/providers/scan")({
  server: {
    handlers: {
      GET: () => {
        try {
          const result = scanExternalProviders();
          return Response.json({
            providers: result.providers,
            warnings: result.warnings,
          });
        } catch (err) {
          return Response.json(
            { error: `Scan failed: ${err instanceof Error ? err.message : String(err)}` },
            { status: 500 },
          );
        }
      },
    },
  },
});
