/**
 * Sync progress interface
 */
export interface SyncProgress {
    isSyncing: boolean;
    pendingChanges: number;
    isOnline: boolean;
    lastError?: string;
}

/**
 * Get sync status from local database
 */
export async function getSyncStatus(): Promise<SyncProgress> {
    if (!window.electron) {
        return {
            isSyncing: false,
            pendingChanges: 0,
            isOnline: navigator.onLine
        };
    }

    try {
        const result = await window.electron.dbGetSyncStatus();
        if (!result.success) {
            throw new Error(result.error);
        }
        return result.data;
    } catch (error) {
        console.error('Failed to get sync status:', error);
        return {
            isSyncing: false,
            pendingChanges: 0,
            isOnline: navigator.onLine,
            lastError: error instanceof Error ? error.message : 'Unknown error'
        };
    }
}

/**
 * Get pending changes to sync
 */
export async function getPendingChanges(limit: number = 100) {
    if (!window.electron) {
        return [];
    }

    try {
        const result = await window.electron.dbGetPendingChanges(limit);
        if (!result.success) {
            throw new Error(result.error);
        }
        return result.data || [];
    } catch (error) {
        console.error('Failed to get pending changes:', error);
        return [];
    }
}
