
/**
 * 데이터 백업 및 복원 관련 기능
 */
import { BackupData } from './types';

/**
 * 현재 로컬 데이터를 백업
 */
export const backupLocalData = (): BackupData => {
  return {
    budgetData: localStorage.getItem('budgetData'),
    categoryBudgets: localStorage.getItem('categoryBudgets'),
    transactions: localStorage.getItem('transactions')
  };
};

/**
 * 백업 데이터를 로컬 스토리지에 복원
 */
export const restoreLocalData = (backup: BackupData): void => {
  if (backup.budgetData) {
    localStorage.setItem('budgetData', backup.budgetData);
  }
  
  if (backup.categoryBudgets) {
    localStorage.setItem('categoryBudgets', backup.categoryBudgets);
  }
  
  if (backup.transactions) {
    localStorage.setItem('transactions', backup.transactions);
  }
  
  // UI 업데이트 이벤트 발생
  window.dispatchEvent(new Event('budgetDataUpdated'));
  window.dispatchEvent(new Event('categoryBudgetsUpdated'));
  window.dispatchEvent(new Event('transactionUpdated'));
};
