'use server';

import { executeServerAction, type ActionResult } from '@/lib/api/execute-server-action';
import { buildApiUrl } from '@/lib/api/query-params';
import type { AccountLedgerResponse, JournalEntryDetail } from './types';

// ===== 계정별원장 조회 =====
export async function getAccountLedger(params: {
  startDate: string;
  endDate: string;
  accountCode: string;
}): Promise<ActionResult<AccountLedgerResponse>> {
  return executeServerAction<AccountLedgerResponse>({
    url: buildApiUrl('/api/v1/account-ledger', {
      start_date: params.startDate,
      end_date: params.endDate,
      account_code: params.accountCode,
    }),
    errorMessage: '계정별원장 조회에 실패했습니다.',
  });
}

// ===== 전표 상세 조회 (드릴다운) =====
export async function getJournalEntryDetail(
  id: number
): Promise<ActionResult<JournalEntryDetail>> {
  return executeServerAction<JournalEntryDetail>({
    url: buildApiUrl(`/api/v1/general-journal-entries/${id}`),
    errorMessage: '전표 상세 조회에 실패했습니다.',
  });
}
