using Febe.Core.Domain; namespace Febe.Core.Storage; /// Accounts (spec §4.2, §8.3 account). public interface IAccountStore { Task GetAsync(long accountId, CancellationToken ct = default); /// The account with this Instagram identifier: the identity of an account. Task FindByInstagramIdAsync(string instagramId, CancellationToken ct = default); /// Case-insensitive lookup by current user name. Task FindByUsernameAsync(string username, CancellationToken ct = default); /// Alberto's own profile («Tu»), when known. Task GetMineAsync(CancellationToken ct = default); /// All accounts, ordered by user name. Task> ListAsync(CancellationToken ct = default); /// /// The stored text of «Cosa scaricare prima» of the accounts that have an order of their own (spec §4.4), by local /// key; the accounts that follow the general order are left out. Read by the queue of the files at every batch. /// Task> ListDownloadOrdersAsync(CancellationToken ct = default); /// All accounts with their counts; «new» counts are entries discovered at or after . Task> ListSummariesAsync(DateTimeOffset newSince, CancellationToken ct = default); Task GetStatsAsync(long accountId, CancellationToken ct = default); /// Adds an account and returns it with its key. /// Another account has the same Instagram identifier, or is already «Tu». Task AddAsync(Account account, CancellationToken ct = default); /// Replaces every field of an existing account (settings screen). Task UpdateAsync(Account account, CancellationToken ct = default); Task SetStateAsync(long accountId, AccountState state, DateTimeOffset at, UnreachableReason? reason = null, CancellationToken ct = default); /// Updates last and next check times. Null values leave the stored value unchanged. Task UpdateChecksAsync(long accountId, AccountCheckTimes times, CancellationToken ct = default); /// Stores the backfill resume point; marks the backfill as finished. Task SetBackfillAsync(long accountId, string? cursor, DateTimeOffset? completedAt, CancellationToken ct = default); /// /// Records a rename seen in the data (spec §4.2): updates the user name, keeps the folder (a default folder is /// pinned to the old name) and raises the «Renamed» notice. /// Task RenameAsync(long accountId, string newUsername, DateTimeOffset at, CancellationToken ct = default); /// Adds notices (e.g. unrecognized format) to an account. Task AddNoticesAsync(long accountId, AccountNotices notices, DateTimeOffset at, CancellationToken ct = default); /// Clears notices once Alberto has seen them. Task ClearNoticesAsync(long accountId, AccountNotices notices, CancellationToken ct = default); /// /// Removes the account record and, by cascade, its entries, files records and highlights. Files on disk are not /// touched: removing an account with its files is a library operation, and the default is to keep them and make /// the account «Solo archivio» (spec §4.2). /// Task DeleteAsync(long accountId, CancellationToken ct = default); } /// Check times of an account; null values are left unchanged. public sealed record AccountCheckTimes { public DateTimeOffset? LastProfileCheckAt { get; init; } public DateTimeOffset? NextProfileCheckAt { get; init; } public DateTimeOffset? LastStoriesCheckAt { get; init; } public DateTimeOffset? NextStoriesCheckAt { get; init; } /// Profile facts read with the check (null: unchanged). public int? PostCount { get; init; } public bool? IsPrivate { get; init; } public bool? IsFollowed { get; init; } public string? DisplayName { get; init; } } /// A unique constraint refused a record (duplicate Instagram identifier, second «Tu», ...). public sealed class DuplicateRecordException : Exception { public DuplicateRecordException() { } public DuplicateRecordException(string message) : base(message) { } public DuplicateRecordException(string message, Exception innerException) : base(message, innerException) { } }