import { NextResponse } from 'next/server';
import { pingBot } from '@/lib/grpc';

export async function GET(request: Request) {
  const { searchParams } = new URL(request.url);
  const msg = searchParams.get('msg') || 'Dashboard-to-Bot';

  try {
    const data = await pingBot(msg);
    return NextResponse.json({ success: true, ...data });
  } catch (error: any) {
    console.error('gRPC Ping Error:', error);
    return NextResponse.json(
      { success: false, error: error.message },
      { status: 500 }
    );
  }
}
