using PLib.Application.Metadata;
using PLib.Domain.Videos;
namespace PLib.Application.Library;
/// Use cases the UI needs in order to show and refresh the video library.
public interface ILibraryService
{
/// Everything currently stored in the library, newest first.
Task> GetLibraryAsync(CancellationToken cancellationToken = default);
///
/// Reconciles the library with the configured folders and then fills in metadata and
/// poster frames for anything that is missing them, streaming progress as it goes.
///
IAsyncEnumerable ScanAsync(
IReadOnlyList folders,
CancellationToken cancellationToken = default);
///
/// What each kind of derived data currently costs, one entry per
/// , so the user can see what clearing it would free.
///
Task> GetDataUsageAsync(CancellationToken cancellationToken = default);
///
/// Throws the named kinds of derived data away — files as well as the references to them —
/// so the next scan rebuilds them from scratch. Useful after changing a setting that
/// governs how they are produced, or when one of them is suspected of being wrong.
///
Task ResetAsync(LibraryDataKind kinds, CancellationToken cancellationToken = default);
/// Remembers where playback stopped so the video can be resumed later.
Task SaveProgressAsync(Guid videoId, TimeSpan position, CancellationToken cancellationToken = default);
///
/// Groups of videos that look alike, by perceptual hash. Videos without a hash, and
/// groups of one, are left out.
///
///
/// How many differing bits still count as the same video. Zero means visually identical;
/// the useful range for re-encodes is a handful of bits.
///
Task>> FindDuplicatesAsync(
int maxDistance,
CancellationToken cancellationToken = default);
/// One video with its labels loaded, or null if it is gone.
Task GetVideoWithLabelsAsync(Guid videoId, CancellationToken cancellationToken = default);
/// Every tag and collection in the library, alphabetically.
Task> GetLabelsAsync(CancellationToken cancellationToken = default);
/// Every label with its video count, for the browsing tabs.
Task> GetLabelSummariesAsync(CancellationToken cancellationToken = default);
///
/// Attaches a label to a video, creating it if this is the first time the name is used.
/// Returns the label, whether it was new or not.
///
Task AttachLabelAsync(
Guid videoId,
string name,
LabelKind kind,
CancellationToken cancellationToken = default);
Task DetachLabelAsync(Guid videoId, Guid labelId, CancellationToken cancellationToken = default);
///
/// Asks every configured metadata source what it has for this video's fingerprint.
///
///
/// Nothing calls this on its own: reaching out to a remote service about the user's files
/// happens when the user presses the button, and at no other time.
///
Task FindMetadataAsync(Guid videoId, CancellationToken cancellationToken = default);
///
/// Writes a match onto the video: title, description, and a label per tag, performer and
/// studio. Labels already on the video are kept — applying a match adds, never prunes.
///
Task ApplyMetadataAsync(
Guid videoId,
VideoMetadataMatch match,
CancellationToken cancellationToken = default);
///
/// Asks the sources about every fingerprinted video in the library, streaming what it
/// finds. Like the single lookup, it only ever runs because the user started it.
///
IAsyncEnumerable ScanMetadataAsync(
MetadataScanRequest request,
CancellationToken cancellationToken = default);
}