// Copyright (C) 2025, The Duplicati Team
// https://duplicati.com, hello@duplicati.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
#nullable enable
namespace Duplicati.Library.Interface;
public interface IRestoreDestinationProvider : IDisposable
{
///
/// The target destination path
///
string TargetDestination { get; }
///
/// Initializes the restore destination provider
///
/// The cancellation token
/// An awaitable task
Task Initialize(CancellationToken cancel);
///
/// Finalizes the restore destination provider
///
/// A callback to report progress
/// The cancellation token
/// An awaitable task
Task Finalize(Action? progressCallback, CancellationToken cancel);
///
/// Tests the provider connection
///
/// The cancellation token
/// An awaitable task
Task Test(CancellationToken cancellationToken);
///
/// Creates the folder at the given path if it does not exist
///
/// The path to create
/// The cancellation token
/// true if the folder was created, false if it already existed
Task CreateFolderIfNotExists(string path, CancellationToken cancel);
///
/// Checks if a file exists at the given path
///
/// The path to check
/// The cancellation token
/// true if the file exists, false otherwise
Task FileExists(string path, CancellationToken cancel);
///
/// Restores a file to the given path
///
/// The path to restore to
/// The cancellation token
/// A stream to write the restored data to
Task OpenWrite(string path, CancellationToken cancel);
///
/// Opens a file for reading at the given path
///
/// The path to the file
/// The cancellation token
/// A stream to read the file from
Task OpenRead(string path, CancellationToken cancel);
///
/// Opens a file for reading and writing at the given path
///
/// The path to the file
/// The cancellation token
/// A stream to read and write the file from
Task OpenReadWrite(string path, CancellationToken cancel);
///
/// Gets the length of the file at the given path
///
/// The path to the file
/// The cancellation token
/// The length of the file in bytes
Task GetFileLength(string path, CancellationToken cancel);
///
/// Checks if the file at the given path has the read-only attribute set
///
/// The path to the file
/// The cancellation token
/// true if the file has the read-only attribute set, false otherwise
Task HasReadOnlyAttribute(string path, CancellationToken cancel);
///
/// Clears the read-only attribute from the file at the given path
///
/// The path to the file
/// The cancellation token
/// A task that completes when the attribute is cleared
Task ClearReadOnlyAttribute(string path, CancellationToken cancel);
///
/// Restores metadata to the given path
///
/// The path to restore to
/// The metadata to restore
/// Whether to restore symlink metadata
/// Whether to restore permissions
/// The cancellation token
/// true if the metadata was restored, false otherwise
Task WriteMetadata(string path, Dictionary metadata, bool restoreSymlinkMetadata, bool restorePermissions, CancellationToken cancel);
///
/// Deletes a folder at the given path
///
/// The path to delete
/// The cancellation token
/// A task that completes when the deletion is done
Task DeleteFolder(string path, CancellationToken cancel);
///
/// Deletes a file at the given path
///
/// The path to delete
/// The cancellation token
/// A task that completes when the deletion is done
Task DeleteFile(string path, CancellationToken cancel);
///
/// Gets a list of priority files that should be restored first.
/// These files are typically metadata files needed to reconstruct
/// the target structure (e.g., disk geometry, partition tables) before
/// the actual data files are restored.
///
/// A list of file paths that should be restored first, in order of priority.
IList GetPriorityFiles();
}