using Titano.Protocol.Client;
namespace Titano.Uploader.Uploads;
/// How the server answered a successful upload.
public enum UploadOutcome
{
/// Committed after the server checked the SHA-256 (CompleteUploadResponse).
Verified,
/// The server already held this SHA-256 (AlreadyExists).
AlreadyOnServer,
}
/// What the upload needs from the server connection.
public interface IUploadTransport
{
/// True while signed in and reachable; the engine waits otherwise.
bool IsReady { get; }
/// Raised (on the UI thread) when changes.
event EventHandler? ReadyChanged;
///
/// Sends one file whose hash is known. Throws when the server cannot be
/// used right now (offline, signed out, certificate changed); other failures concern this file only.
///
Task<(UploadOutcome Outcome, Guid? FrameId)> UploadAsync(UploadItem item, Guid? sequenceId, string sha256, IProgress progress, CancellationToken ct);
/// Creates a sequence for a "new sequence" batch.
Task CreateSequenceAsync(string? title, CancellationToken ct);
}
/// Why the server cannot be used.
public enum ServerProblem
{
Unreachable,
SignedOut,
CertificateChanged,
}
/// The server cannot take uploads right now; the item goes back in line without spending a retry.
public sealed class ServerUnavailableException(ServerProblem problem, Exception? inner = null)
: Exception("Server unavailable: " + problem, inner)
{
public ServerProblem Problem { get; } = problem;
}