import { getInterests } from "../utils/nocodb";
import { requireAuth } from "../utils/auth";

export default defineEventHandler(async (event) => {
  console.log('[get-interests] Request received');

  // Check authentication (x-tag header OR Keycloak session)
  await requireAuth(event);

  try {
    console.log('[get-interests] Fetching interests...');
    const interests = await getInterests();
    console.log('[get-interests] Successfully fetched interests, count:', interests.list?.length || 0);
    return interests;
  } catch (error) {
    console.error('[get-interests] Error occurred:', error);
    console.error('[get-interests] Error details:', error instanceof Error ? error.message : 'Unknown error');
    throw error;
  }
});
