'use server';

import { verifySession } from '@/lib/auth/dal';
import { fetchPointHistory } from '@/lib/data/repositories/point-account-repository';
import type { PointHistoryEntry } from '@/lib/domain/point-account';
import { POINT_HISTORY_PAGE_SIZE } from '@/lib/domain/point-account-query';

/** 상세내역은 목록 행에 없는 데이터라 팝업이 열릴 때 따로 가져온다(기획 PTS10300001). */
export async function fetchPointHistoryAction(
  accountId: string,
  page: number
): Promise<{ items: PointHistoryEntry[]; totalPages: number }> {
  await verifySession();

  const { items, totalCount } = await fetchPointHistory(
    accountId,
    page,
    POINT_HISTORY_PAGE_SIZE
  );

  return {
    items,
    totalPages: Math.max(1, Math.ceil(totalCount / POINT_HISTORY_PAGE_SIZE)),
  };
}
