import { logger } from './logger';

interface SyncQueueItem {
  table: string;
  operation: 'insert' | 'update' | 'delete';
  data: Record<string, unknown>;
  timestamp: Date;
}

const syncQueue: SyncQueueItem[] = [];

export async function queueFailedSync(
  table: string,
  operation: 'insert' | 'update' | 'delete',
  data: Record<string, unknown>,
): Promise<void> {
  syncQueue.push({
    table,
    operation,
    data,
    timestamp: new Date(),
  });

  logger.warn(`Queued failed sync: ${operation} on ${table}`, {
    table,
    operation,
    queueSize: syncQueue.length,
  });
}

export function getSyncQueue(): SyncQueueItem[] {
  return [...syncQueue];
}

export function clearSyncQueue(): void {
  syncQueue.length = 0;
}
