using System;
using System.Collections.Generic;
using System.Data;
using System.Threading;
using System.Threading.Tasks;
using Duplicati.Library.Interface;
using Duplicati.Library.Main.Database;
using Duplicati.Library.Main.Volumes;
using Duplicati.Library.Utility;
using IFileEntry = Duplicati.Library.Interface.IFileEntry;
#nullable enable
namespace Duplicati.Library.Main;
///
/// Interface for the backend manager
///
internal interface IBackendManager : IDisposable
{
///
/// Uploads a block volume to the backend, including an optional index volume
///
/// The block volume to upload
/// The index volume to upload, if any
/// The action to call when the index volume is finished
/// Whether to wait for the upload to complete
/// The action to call when the database should be updated
/// The cancellation token
/// An awaitable task
Task PutAsync(VolumeWriterBase blockVolume, IndexVolumeWriter? indexVolume, Func? indexVolumeFinished, bool waitForComplete, Func? onDbUpdate, CancellationToken cancelToken);
///
/// Uploads a file to the backend without encryption
///
/// The name of the file to upload to
/// The file to upload
/// The cancellation token
/// An awaitable task
Task PutVerificationFileAsync(string remotename, TempFile tempFile, CancellationToken cancelToken);
///
/// Waits for the backend queue to be empty
///
/// The cancellation token
/// An awaitable task
Task WaitForEmptyAsync(CancellationToken cancellationToken);
///
/// Waits for the backend queue to be empty and flushes any pending messages to the database
///
/// The database to write pending messages to
/// The cancellation token
/// An awaitable task
Task WaitForEmptyAsync(LocalDatabase database, CancellationToken cancellationToken);
///
/// Lists the files on the backend
///
/// The cancellation token
/// An enumerable of file entries
Task> ListAsync(CancellationToken cancelToken);
///
/// Decrypts the given file and returns the decrypted file
///
/// The file to decrypt
/// The name of the file. Used for detecting encryption algorithm if not specified in options or if it differs from the options
/// The Duplicati options
/// The decrypted file
TempFile DecryptFile(TempFile volume, string volume_name, Options options);
///
/// Deletes a file on the backend
///
/// The name of the file to delete
/// The size of the file to delete, or -1 if not known
/// Whether to wait for the delete to complete
/// The cancellation token
/// An awaitable task
Task DeleteAsync(string remotename, long size, bool waitForComplete, CancellationToken cancelToken);
///
/// Gets the quota information for the backend
///
/// The cancellation token
/// The quota information, or null if not available or disabled
Task GetQuotaInfoAsync(CancellationToken cancelToken);
///
/// Gets a file with the hash and size
///
/// The name of the file to get
/// The hash of the file to get, or null if not known
/// The size of the file to get, or -1 if not known
/// The cancellation token
/// The file, hash, and size
Task<(TempFile File, string Hash, long Size)> GetWithInfoAsync(string remotename, string hash, long size, CancellationToken cancelToken);
///
/// Gets a file from the backend
///
/// The name of the file to get
/// The hash of the file to get, or null if not known
/// The size of the file to get, or -1 if not known
/// The cancellation token
/// The downloaded file
Task GetAsync(string remotename, string hash, long size, CancellationToken cancelToken);
///
/// Gets a file from the backend without decrypting it
///
/// The name of the remote volume
/// The hash of the volume
/// The size of the volume
/// The cancellation token
/// The downloaded file
Task GetDirectAsync(string remotename, string hash, long size, CancellationToken cancelToken);
///
/// Performs a download of the files specified, with pre-fetch to overlap the download and processing
///
/// The volumes to download
/// The cancellation token
/// The downloaded files, hash, size, and name
IAsyncEnumerable<(TempFile File, string Hash, long Size, string Name)> GetFilesOverlappedAsync(IEnumerable volumes, CancellationToken cancelToken);
///
/// Flushes the database messages to the database
///
/// The database to write to
/// The cancellation token
///
Task FlushPendingMessagesAsync(LocalDatabase database, CancellationToken cancellationToken);
///
/// Updates the throttle values for upload and download
///
/// The maximum upload speed in bytes per second
/// The maximum download speed in bytes per second
void UpdateThrottleValues(long maxUploadPrSecond, long maxDownloadPrSecond);
}