using Febe.Core.Domain; using Febe.Core.Storage; namespace Febe.Core.Export; /// What a «Copia in…» is asked for (spec §4.10 «Manuale sempre»). public abstract record ExportSelection { private ExportSelection() { } /// Files by id: a selection of «Tutte le foto», a file of the viewer. public sealed record Media(IReadOnlyList MediaIds) : ExportSelection; /// Entries by id: a grouped selection, an entry of the viewer. public sealed record Entries(IReadOnlyList EntryIds) : ExportSelection; /// The current filter («Copia i file in…» of the CSV menu). public sealed record Filter(LibraryFilter LibraryFilter, MosaicMode Mode) : ExportSelection; /// Every file of an account (the account card). public sealed record Account(long AccountId) : ExportSelection; } /// How the instants of «Fotogrammi» are chosen (spec §4.10 «Fotogrammi»). public enum FrameMode { /// «Questo istante»: one frame at . At, /// «Uno ogni k secondi»: at 0, k, 2k… before the end. Every, /// «N in tutto»: N frames spread over the video, each in the middle of its share. Count, } /// A request of frames of videos, in a photo format (Jpg, Png or WebpLossless). public sealed record ExportFramesRequest(FrameMode Mode, TimeSpan? At, TimeSpan? Every, int? Count, ExportFormat Format); /// /// The formats of «Copia in…» for this request only (tappa E3, D1): null keeps the destination's (or the general /// settings'). A photo format or Original for photos; Mp4 or Original for videos. /// public sealed record ExportFormatChoice(ExportFormat? Photo, ExportFormat? Video); /// «Copia di nuovo» of one copy row (tappa E3, D11): the form of that row, looked up only by its exact identity. /// The instant of a frame row; null otherwise. public sealed record ExportCopyRequest(ExportVariant Variant, ExportFormat Format, TimeSpan? FrameAt); /// A «Copia in…»: what to copy, whether «Tolti» and «Superati» are copied again (D9), who asked. /// The formats of this request («Copia in…» → «Cambia»); null: those of the destination. /// Not null: a frames job («Fotogrammi…» → «Nella cartella delle copie»), videos only. /// «Copia di nuovo» of one copy row, only with a selection of one file. public sealed record ExportJobRequest( ExportSelection Selection, bool CopyAgain = false, ExportRunOrigin Origin = ExportRunOrigin.Manual, ExportFormatChoice? Formats = null, ExportFramesRequest? Frames = null, ExportCopyRequest? Exact = null); /// /// What a «Copia in…» would do (database only, decisions D3 and D9 of tappa E2). Each file goes to the effective /// destination of its account (D5). /// /// Files to write. /// Their bytes. /// Already in their destination (or, with «Una copia sola», copied for another account). /// /// «Tolti o superati»: never copied again by themselves. With they are also /// counted in and , since they will be written. /// /// «Esporta questo account» off, no destination, or a content type the destination does not take. /// «File non presente in libreria». /// Each destination that gets files, with whether it answers now. /// /// A folder of the copies exists (the general one or one of an account, in use): when nothing is to copy, the dialog /// says «no folder» only when this is false, not because no destination gets files. /// public sealed record ExportPlan( int Files, long Bytes, int AlreadyCopied, int RemovedOrSuperseded, int NotExported, int Missing, IReadOnlyList Destinations, bool HasDestination = true) { public static ExportPlan Empty { get; } = new(0, 0, 0, 0, 0, 0, []); /// /// Files predicted to be copied as they are, by kind («3 HEIC copiati come sono»): a prediction from the names /// («circa»), the copy decides on the bytes (tappa E3). /// public IReadOnlyList AsIs { get; init; } = []; /// Files predicted to be converted. public int Converted { get; init; } /// «Con perdita»: at least one file predicted converted to JPG, or JPG frames (D7 of tappa E3). public bool Lossy { get; init; } /// Frames job: the due videos. public int Videos { get; init; } /// Frames job: the photos of the selection, skipped («Le 4 foto si saltano»). public int PhotosSkipped { get; init; } /// Frames job: the frames to write (also in ); «circa» for a video of unknown length. public int Frames { get; init; } /// Frames job: videos that would give more than frames (the job is refused). public int OverCap { get; init; } } /// Files of a plan copied as they are, of one kind («HEIC», «AVIF», «raw», «GIF», «WebM»). public sealed record ExportPlanAsIs(string Label, int Files); /// A destination of a plan. /// The account of an own folder; null for the general folder. /// Files to write there. /// The destination is paused (its last check failed). /// Why it cannot be written now (not reachable, not mounted, paused), in Italian; null when fine. /// Free space, when it can be measured. public sealed record ExportPlanDestination( long DestinationId, string Label, string RootPath, ExportScope Scope, string? Username, int Files, long Bytes, bool Paused, string? Problem, long? FreeBytes); /// What the export job is doing. public enum ExportPhase { Preparing, /// «Controlla le copie». Checking, /// An engine session is running: copies wait for it to end (decision D11). WaitingForSession, Copying, Finished, } /// Progress of the export job, for the progress card (polled, D20). /// The job's run being worked on; null for «Controlla le copie» and when nothing ever ran. /// Bytes of the files still pending when the run (re)started, plus those done since; 0 when unknown. public sealed record ExportProgress( long? RunId, ExportPhase Phase, int FilesDone, int FilesTotal, long BytesDone, long BytesTotal, string? CurrentFile, string? DestinationLabel, IReadOnlyDictionary ByState, DateTimeOffset UpdatedAt) { /// 0..1: by bytes when known, otherwise by files. public double Fraction => BytesTotal > 0 ? Math.Clamp((double)BytesDone / BytesTotal, 0, 1) : FilesTotal > 0 ? Math.Clamp((double)FilesDone / FilesTotal, 0, 1) : 0; } /// What ExportService.StartAsync did: one run per destination (D6), and the plan it followed. public sealed record ExportStart(IReadOnlyList Runs, ExportPlan Plan); /// What «Riprova» of a paused destination did: the reason it is still paused (null: it answers), and the jobs resumed. public sealed record ExportRetry(string? Problem, IReadOnlyList Resumed); /// The export job ended (however it ended): the runs it worked on, and whether copies may have changed. public sealed record ExportJobFinished(IReadOnlyList RunIds, bool CopiesChanged);