
import { useCallback } from 'react';
import { Transaction } from '@/components/TransactionCard';
import { useBudget } from '@/contexts/BudgetContext';

export const useTransactionsOperations = (transactions: Transaction[]) => {
  const { updateTransaction: budgetUpdateTransaction, deleteTransaction: budgetDeleteTransaction } = useBudget();

  // 트랜잭션 업데이트 함수
  const updateTransaction = useCallback((updatedTransaction: Transaction): void => {
    try {
      budgetUpdateTransaction(updatedTransaction);
    } catch (error) {
      console.error('트랜잭션 업데이트 중 오류:', error);
    }
  }, [budgetUpdateTransaction]);

  // 트랜잭션 삭제 함수
  const deleteTransaction = useCallback(async (id: string): Promise<boolean> => {
    try {
      budgetDeleteTransaction(id);
      return true;
    } catch (error) {
      console.error('트랜잭션 삭제 중 오류:', error);
      return false;
    }
  }, [budgetDeleteTransaction]);

  return {
    updateTransaction,
    deleteTransaction
  };
};
