import { NextResponse } from 'next/server';
import { withErrorHandler } from '@server/middleware/withErrorHandler';
import { withAuth, AuthedRequest } from '@server/middleware/withAuth';
import { getAdminRestaurantDetail } from '@server/services/admin.service';
import { ForbiddenError, NotFoundError } from '@server/errors';

export const GET = withErrorHandler(
  withAuth(async (req: AuthedRequest, context: { params: Promise<Record<string, string>> }) => {
    if (req.session.role !== 'superadmin' && req.session.role !== 'support') {
      throw new ForbiddenError();
    }
    const { id } = await context.params;
    const detail = await getAdminRestaurantDetail(id);
    if (!detail) throw new NotFoundError('Restaurant not found');
    return NextResponse.json({ restaurant: detail });
  })
);
