'use server';

import {
  PageViewAction,
  createPageViewLog,
} from '~/lib/services/audit/pageView.service';

import { loadCurrentUserAccount } from '../../_lib/server/load-user-account';

export async function logAnalysisResultsNavigateAction(
  analysisOrderId: string,
) {
  const { account } = await loadCurrentUserAccount();
  if (!account) {
    throw new Error('Account not found');
  }
  await createPageViewLog({
    accountId: account.id,
    action: PageViewAction.VIEW_ANALYSIS_RESULTS_FROM_ORDER,
    extraData: {
      analysisOrderId,
    },
  });
}
