using Febe.Core.Domain;
namespace Febe.Core.Storage;
/// Entries (spec §4.3, §8.3 entry) and the library queries of the interface (spec §4.6).
public interface IEntryStore
{
Task GetAsync(long entryId, CancellationToken ct = default);
Task GetWithMediaAsync(long entryId, CancellationToken ct = default);
/// The entry with this identity, in any state (deleted included).
Task FindAsync(long accountId, EntryKind kind, string instagramId, CancellationToken ct = default);
///
/// «Is this Instagram identifier known?» for (account, kind), in any state — deleted entries count as known so
/// they are never downloaded again (spec §4.6).
///
Task IsKnownAsync(long accountId, EntryKind kind, string instagramId, CancellationToken ct = default);
/// Which of these identifiers are already known for (account, kind), in any state. For readers: one query per page.
Task> GetKnownInstagramIdsAsync(long accountId, EntryKind kind, IReadOnlyCollection instagramIds, CancellationToken ct = default);
/// Entries of an account with this Instagram identifier, any kind and state (e.g. a story that entered a highlight).
Task> FindByInstagramIdAsync(long accountId, string instagramId, CancellationToken ct = default);
///
/// An entry of (account, kind) published within of :
/// recognizes imported entries that have no Instagram identifier (spec §9.5, two seconds).
///
Task FindByPublicationTimeAsync(long accountId, EntryKind kind, DateTimeOffset publishedAt, TimeSpan tolerance, CancellationToken ct = default);
///
/// Adds an entry with its files in one transaction. Idempotent on (account, kind, Instagram identifier): when the
/// entry is already known, nothing changes and the stored entry is returned with Created = false.
/// Positions of the files must be distinct.
///
Task AddAsync(Entry entry, IReadOnlyList media, CancellationToken ct = default);
/// Adds many entries in one transaction (import, rebuild). Same semantics as .
Task> AddManyAsync(IReadOnlyList entries, CancellationToken ct = default);
/// Replaces the mutable fields of an entry (Instagram identifier, code, caption, author, state, dates).
Task UpdateAsync(Entry entry, CancellationToken ct = default);
///
/// Marks a post as a reel (spec §7.2, «Cosa scaricare prima»), writing only that flag; other kinds are left as they are.
/// A reel never goes back to a plain post: keeps the flag once set.
///
Task MarkReelAsync(long entryId, CancellationToken ct = default);
Task SetStateAsync(long entryId, EntryState state, CancellationToken ct = default);
/// Recomputes the state of an entry from its files ().
Task RecomputeStateAsync(long entryId, CancellationToken ct = default);
///
/// «Eliminato»: the entry stays without files so it is not downloaded again (spec §4.6). Its files become
/// and lose their path and perceptual hash; SHA-256 and size are kept. Deleting files on disk is the caller's job.
///
Task MarkDeletedAsync(long entryId, DateTimeOffset at, CancellationToken ct = default) => MarkDeletedAsync(entryId, at, [], ct);
///
/// As , and in the same transaction the
/// conversions for the library of its files: the queue and the failures (Pending, Failed) go, and the rows of
/// (whose converted file goes or is gone) become «Tolto». Other converted rows stay.
///
Task MarkDeletedAsync(long entryId, DateTimeOffset at, IReadOnlyCollection removedConversionIds, CancellationToken ct = default);
///
/// «Eliminalo e lascia che torni»: removes the record (files records and highlight links by cascade). Conversions
/// without a file left (Pending, Failed, Removed) go with it; a Converted or Superseded one makes it fail with
/// (its file would be forgotten): use .
///
Task RemoveAsync(long entryId, CancellationToken ct = default);
///
/// «Eliminalo e lascia che torni» from «Elimina dalla libreria»: removes the record and every conversion of its files
/// in one transaction, and returns the conversions removed (their converted files are the caller's to delete).
///
Task> RemoveWithConversionsAsync(long entryId, CancellationToken ct = default);
/// Entries of an account ordered by publication time, newest first (account tabs, collection pipeline).
Task> ListByAccountAsync(long accountId, EntryListOptions? options = null, CancellationToken ct = default);
///
/// What a recipe saved (spec §7.9, thumbnails of the history of the Dashboard): the entries Febe downloaded (never
/// the imported ones) discovered in [from, to], of the account or, with null, of every account (the Giro dei
/// seguiti), newest first, at most , with how many there are in all.
///
Task ListDiscoveredAsync(long? accountId, DateTimeOffset from, DateTimeOffset to, int limit, CancellationToken ct = default);
/// Entries of (account, kind) discovered in [from, to): per-account daily backfill limit.
Task CountDiscoveredAsync(long accountId, EntryKind kind, DateTimeOffset from, DateTimeOffset to, CancellationToken ct = default);
/// A window of the library mosaic with keyset paging: stays fast over 200,000 entries.
Task QueryLibraryAsync(LibraryQuery query, CancellationToken ct = default);
Task GetLibraryTotalsAsync(LibraryFilter filter, CancellationToken ct = default);
///
/// Entries (or, with , files) per local calendar day in Alberto's zone, newest day
/// first. A day without files is left out in that mode. In that mode the files are those in the library
/// (downloaded or imported), the tiles of «Tutte le foto», with «Foto» and «Video» only the files of that kind; their
/// total is the sum of the days (one pass over the files, not a second count).
///
Task> CountLibraryByDayAsync(LibraryFilter filter, TimeZoneInfo zone, MosaicMode mode = MosaicMode.Grouped, CancellationToken ct = default);
/// Tiles for given entries, in the given order (e.g. the items of a highlight collection).
Task> GetTilesAsync(IReadOnlyList entryIds, CancellationToken ct = default);
}
/// Entries saved by a recipe: the first ones, newest first, and how many in all.
public sealed record ArrivedEntries(IReadOnlyList EntryIds, int Total);