import { BackgroundJob } from '../background';
import { DownloadContext } from '../context';
import { Event, IEventHub } from '../events';
import { IDownloadApiClient } from '../external';
import { FileProgressUpdatedEvent } from '../models';
import { FileStateChangedEvent } from '../models/DownloadFile';
import { IDownloadChunksRepository, IDownloadFilesRepository, IDownloadTransactionsRepository } from '../repositories';
import { IStorage } from '../storage';
import { ILocker, ILogger, IRetrier } from '../utilities';
import { DownloadDatabase } from './db';
import { GetFileQuery, ListAllFilesQuery } from './queries';

export type Constructor<T> = new (...args: any[]) => T;
export type EventHandlerFunc<T extends Event> = (event: T) => Promise<void>;
export declare class DownloadTransactionStartedEvent extends Event {
    static readonly type: string;
}
export declare class RocketModeToggledEvent extends Event {
    readonly enable: boolean;
    static readonly type: string;
    constructor(enable: boolean);
}
export declare class ChunkSizeUpdatedEvent extends Event {
    readonly chunkSize: number;
    static readonly type: string;
    constructor(chunkSize: number);
}
export declare class BecomeLeaderEvent extends Event {
    static readonly type: string;
}
export type IDownloadManager = {
    cancelAllFiles: (ids: string[]) => Promise<void>;
    cancelFile: (fileID: string) => Promise<void>;
    deleteAllFiles: () => Promise<void>;
    deleteFile: (fileID: string) => Promise<void>;
    getChunkSize: () => Promise<number>;
    getDefaultRootName: () => Promise<string | null>;
    getFile: (id: string) => Promise<GetFileQuery.QueryResult>;
    /**
     * Do necessary handling when the user has rejected cookies for downloader
     */
    handleCookiesRejected: () => void;
    isRocketModeEnabled: () => Promise<boolean>;
    listAllFiles: () => Promise<ListAllFilesQuery.QueryResult>;
    on: <T extends Event>(ctor: Constructor<T>, handlerFunc: EventHandlerFunc<T>) => () => void;
    onFileProgressUpdated: (handlerFunc: EventHandlerFunc<FileProgressUpdatedEvent>) => () => void;
    onFileStateChanged: (handlerFunc: EventHandlerFunc<FileStateChangedEvent>) => () => void;
    pauseAllFiles: (ids: string[]) => Promise<void>;
    pauseFile: (fileID: string) => Promise<void>;
    registerDefaultRoot: () => Promise<string | null>;
    registerDownload: (transactionID: string) => Promise<string | null>;
    removeDefaultRoot: () => Promise<void>;
    restart: () => Promise<void>;
    resumeAllFiles: (ids: string[]) => Promise<void>;
    resumeFile: (fileID: string) => Promise<void>;
    retryAllFiles: (ids: string[]) => Promise<void>;
    retryFile: (fileID: string) => Promise<void>;
    start: (enableRocketMode: boolean, keepDownloading: boolean) => Promise<void>;
    startDownload: (transactionID: string, location: string) => Promise<void>;
    toggleRocketMode: (enable: boolean) => Promise<void>;
    updateChunkSize: (chunkSize: number) => Promise<void>;
};
type DownloaderKeys = keyof IDownloadManager;
type DownloadManagerEventRegistrationFunc = Extract<DownloaderKeys, `${'on'}${string}`>;
export type DownloadManagerInvokableFunc = Exclude<DownloaderKeys, DownloadManagerEventRegistrationFunc>;
export declare class DownloadManager implements IDownloadManager {
    readonly context: DownloadContext;
    readonly downloadDatabase: DownloadDatabase;
    readonly downloadTransactionsRepo: IDownloadTransactionsRepository;
    readonly downloadFilesRepo: IDownloadFilesRepository;
    readonly downloadChunksRepo: IDownloadChunksRepository;
    readonly downloadApiClient: IDownloadApiClient;
    readonly storage: IStorage;
    readonly eventHub: IEventHub;
    readonly logger: ILogger;
    readonly retrier: IRetrier;
    readonly locker: ILocker;
    private started;
    private backgroundJobs;
    private backgroundJobsStartTimeouts;
    private rocketModeEnabled;
    constructor(context: DownloadContext, downloadDatabase: DownloadDatabase, downloadTransactionsRepo: IDownloadTransactionsRepository, downloadFilesRepo: IDownloadFilesRepository, downloadChunksRepo: IDownloadChunksRepository, downloadApiClient: IDownloadApiClient, storage: IStorage, eventHub: IEventHub, logger: ILogger, retrier: IRetrier, locker: ILocker);
    handleCookiesRejected(): void;
    private setupBackgroundJobs;
    isRocketModeEnabled(): Promise<boolean>;
    private internalToggleRocketMode;
    toggleRocketMode(enable: boolean): Promise<void>;
    getChunkSize(): Promise<number>;
    private internalUpdateChunkSize;
    updateChunkSize(chunkSize: number): Promise<void>;
    private startBackgroundJobs;
    private stopBackgroundJobs;
    runOnce<T extends BackgroundJob>(ctor: Constructor<T>, limit?: number): Promise<void>;
    start(enableRocketMode: boolean, keepDownloading: boolean): Promise<void>;
    restart(): Promise<void>;
    getDefaultRootName(): Promise<string | null>;
    removeDefaultRoot(): Promise<void>;
    registerDefaultRoot(): Promise<string | null>;
    registerDownload(transactionID: string): Promise<string | null>;
    startDownload(transactionID: string, location: string): Promise<void>;
    pauseFile(fileID: string): Promise<void>;
    resumeFile(fileID: string): Promise<void>;
    cancelFile(fileID: string): Promise<void>;
    retryFile(fileID: string): Promise<void>;
    private batchAction;
    pauseAllFiles(ids: string[]): Promise<void>;
    resumeAllFiles(ids: string[]): Promise<void>;
    cancelAllFiles(ids: string[]): Promise<void>;
    retryAllFiles(ids: string[]): Promise<void>;
    deleteFile(fileID: string): Promise<void>;
    deleteAllFiles(): Promise<void>;
    on<T extends Event>(ctor: Constructor<T>, handlerFunc: EventHandlerFunc<T>): () => void;
    onFileProgressUpdated(handlerFunc: EventHandlerFunc<FileProgressUpdatedEvent>): () => void;
    onFileStateChanged(handlerFunc: EventHandlerFunc<FileStateChangedEvent>): () => void;
    listAllFiles(): Promise<ListAllFilesQuery.QueryResult>;
    getFile(id: string): Promise<GetFileQuery.QueryResult>;
}
export declare class DownloadManagerBuilder {
    readonly context: DownloadContext;
    downloadApiClient?: IDownloadApiClient;
    storage?: IStorage;
    eventHub?: IEventHub;
    logger?: ILogger;
    retrier?: IRetrier;
    locker?: ILocker;
    database?: DownloadDatabase;
    constructor(context?: DownloadContext);
    build(): DownloadManager;
}
export {};
