import { NextResponse } from 'next/server';

import { withAuth, withPermission } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { generateRecommendations } from '@/lib/services/recommendations';

// POST /api/v1/interests/[id]/recommendations/generate
export const POST = withAuth(
  withPermission('interests', 'edit', async (req, ctx, params) => {
    try {
      const recommendations = await generateRecommendations(params.id!, ctx.portId, {
        userId: ctx.userId,
        portId: ctx.portId,
        ipAddress: ctx.ipAddress,
        userAgent: ctx.userAgent,
      });
      return NextResponse.json({ data: recommendations });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
