import { refreshExchangeRates } from '@/server/utils/currency';

/**
 * Scheduled task to refresh currency exchange rates hourly
 * This should be called by a cron job or scheduled task runner
 */
export const refreshCurrencyRatesTask = async () => {
  try {
    console.log('[currency-refresh-task] Starting scheduled currency refresh...');
    
    const result = await refreshExchangeRates();
    
    if (result.success) {
      console.log(`[currency-refresh-task] Successfully refreshed ${result.ratesCount} exchange rates`);
    } else {
      console.error('[currency-refresh-task] Failed to refresh exchange rates:', result.message);
    }
    
    return result;
  } catch (error) {
    console.error('[currency-refresh-task] Error during scheduled refresh:', error);
    return {
      success: false,
      message: 'Error occurred during scheduled refresh'
    };
  }
};

// For environments that support direct cron scheduling
export default refreshCurrencyRatesTask;
