import { NextResponse } from 'next/server';
import { withErrorHandler } from '@server/middleware/withErrorHandler';
import { withAuth, requireSection, AuthedRequest } from '@server/middleware/withAuth';
import { getStats } from '@server/services/gift-cards.service';
import { effectiveBranchId } from '@server/utils/branch-access';
import { requirePlanFeature } from '@server/utils/features';

export const GET = withErrorHandler(
  withAuth(async (req: AuthedRequest) => {
    await requireSection(req, 'gift_cards');
    await requirePlanFeature(req.session.restaurantId!, 'gift_cards');
    const stats = await getStats(req.session.restaurantId!, effectiveBranchId(req.session));
    return NextResponse.json({ stats });
  })
);
