import { NextResponse } from 'next/server';
import { withErrorHandler } from '@server/middleware/withErrorHandler';
import { withAuth, requireSection, AuthedRequest } from '@server/middleware/withAuth';
import { isSipFeatureEnabled } from '@/shared/config/sip-feature';
import { isRestaurantSipEnabled } from '@server/middleware/withSipFeature';

// Always returns 200 — clients use the boolean to hide UI without leaking
// whether the feature exists at all on this deployment.
export const GET = withErrorHandler(
  withAuth(async (req: AuthedRequest) => {
    await requireSection(req, 'telephone');
    const platform = isSipFeatureEnabled();
    const restaurant = platform && req.session.restaurantId
      ? await isRestaurantSipEnabled(req.session.restaurantId)
      : false;
    return NextResponse.json({ enabled: platform && restaurant, platform_enabled: platform });
  })
);
