/**
 * Error Recovery Utilities
 */

export const withRetry = async <T>(
  fn: () => Promise<T>,
  options: { retries?: number; delay?: number } = {}
): Promise<T> => {
  const { retries = 3, delay = 1000 } = options;

  for (let i = 0; i < retries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (i === retries - 1) throw error;
      await new Promise(r => setTimeout(r, delay * Math.pow(2, i)));
    }
  }
  throw new Error('Retry failed');
};

// Error recovery info type
export interface RecoveryInfo {
  canvasId: string;
  errorMessage: string;
  metadata?: any;
  timestamp: number;
}

// Error recovery object for canvas state
export const errorRecovery = {
  needsRecovery: (canvasId: string) => false,
  getRecoveryInfo: (): RecoveryInfo | null => null,
  getFormattedRecoveryAge: () => '',
  recoverCanvas: async (canvasId: string): Promise<any> => null,
  clearRecoveryData: () => {},
};
