import { combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
import BroadcastChannelSender from '../../channels/BroadcastChannelSender';
import ParticlesResolverQueue from './services/ParticlesResolverQueue/ParticlesResolverQueue';
import SyncIpfsLoop from './services/SyncIpfsLoop/SyncIpfsLoop';
import SyncTransactionsLoop from './services/SyncTransactionsLoop/SyncTransactionsLoop';
import SyncParticlesLoop from './services/SyncParticlesLoop/SyncParticlesLoop';
export class SyncService {
    constructor(deps) {
        this.channelApi = new BroadcastChannelSender();
        const { dbInstance$, ipfsInstance$ } = deps;
        this.isInitialized$ = combineLatest([dbInstance$, ipfsInstance$]).pipe(map(([dbInstance, ipfsInstance]) => !!dbInstance && !!ipfsInstance));
        this.isInitialized$.subscribe({
            next: (result) => {
                return result && this.channelApi.postServiceStatus('sync', 'started');
            },
            error: (err) => this.channelApi.postServiceStatus('sync', 'error', err),
        });
        const particlesResolver = new ParticlesResolverQueue(deps).start();
        new SyncIpfsLoop(deps, particlesResolver).start();
        new SyncTransactionsLoop(deps, particlesResolver).start();
        new SyncParticlesLoop(deps, particlesResolver).start();
    }
}
//# sourceMappingURL=sync.js.map