import { NextResponse } from 'next/server';
import { withV1ErrorHandler } from '@server/middleware/v1Errors';
import { withApiKey, ApiKeyRequest } from '@server/middleware/withApiKey';
import { RouteContext } from '@server/middleware/withErrorHandler';
import { getCustomer } from '@server/services/customers.service';

export const GET = withV1ErrorHandler(
  withApiKey(async (req: ApiKeyRequest, ctx: RouteContext) => {
    const { id } = await ctx.params;
    const customer = await getCustomer(id, req.apiKey.restaurantId);
    return NextResponse.json({ data: customer });
  }, { permission: 'customers:read' })
);
