using Febe.Core.Domain;
namespace Febe.Core.Storage;
/// Files of entries (spec §8.3 media), hashes and the download queue.
public interface IMediaStore
{
Task GetAsync(long mediaId, CancellationToken ct = default);
/// Files of an entry in position order.
Task> ListByEntryAsync(long entryId, CancellationToken ct = default);
///
/// Every file with this SHA-256 across the whole library, any state, with its entry and account
/// («Già in libreria», spec §9.3; exact duplicates after a download, §9.5).
///
Task> FindBySha256Async(string sha256, CancellationToken ct = default);
///
/// Relative paths of the files of an account that have one, with their entry: recognizes entries without an
/// Instagram identifier (imported) by their files (rebuild, import resume).
///
Task> MapPathsAsync(long accountId, CancellationToken ct = default);
/// Perceptual hashes of the photos present in the library, to load the in-memory index.
Task> LoadPerceptualHashesAsync(CancellationToken ct = default);
///
/// Files waiting to be downloaded, in queue order: stories first (they expire), then by expiry and discovery.
///
Task> ListPendingDownloadsAsync(int limit, CancellationToken ct = default);
/// Files waiting to be downloaded, for one account or overall («lo storico non corre più veloce dei download»).
Task CountPendingDownloadsAsync(long? accountId = null, CancellationToken ct = default);
///
/// Records a file now on disk and recomputes the state of its entry, in one transaction. Returns false, changing
/// nothing, when the file or its entry is «eliminato» (Alberto deleted it while the content was on its way): the
/// caller removes the file it just wrote. Throws when the file record is gone.
///
Task MarkStoredAsync(long mediaId, StoredFile file, MediaState state, DateTimeOffset at, CancellationToken ct = default);
///
/// Records a failed attempt: is Failed, Expired (address expired) or Skipped (a limit).
/// Increments attempts and recomputes the state of the entry.
///
Task MarkFailedAsync(long mediaId, MediaState state, string? error, DateTimeOffset at, CancellationToken ct = default);
///
/// Adds files to an existing entry at positions it does not have yet (files at positions already present are left
/// as they are) and recomputes the state of the entry. Used by «Post singolo» to complete a series that arrived
/// incomplete. Returns the files of the entry in position order.
///
Task> AddToEntryAsync(long entryId, IReadOnlyList media, CancellationToken ct = default);
/// A fresh address read from the page: the file goes back to «da scaricare».
Task UpdateSourceAsync(long mediaId, string? sourceUrl, string? coverUrl, DateTimeOffset seenAt, CancellationToken ct = default);
Task SetThumbnailAsync(long mediaId, bool hasThumbnail, CancellationToken ct = default);
/// Replaces every field of a file record.
Task UpdateAsync(Media media, CancellationToken ct = default);
}