using System.Text.Json; using System.Text.Json.Serialization; using Chronos.Core.Conversion; using Chronos.Core.Import; using Chronos.Core.Model; namespace Chronos.Data.Archiving.Jobs; /// : target = the archive. /// The sequences the scan brings into the index (or whose frames it changes) also get a deep /// analysis in the background, after their light one (Settings › Analysis on the desktop). public sealed record ScanParameters(bool Full, bool DeepAnalysis = false); /// : target = the archive; null sequences = all of them. public sealed record VerifyParameters(IReadOnlyList? SequenceIds); /// and : targets = sequences. public sealed record ImageJobParameters(bool Force); /// : target = the archive. public sealed record MaintenanceParameters(bool DryRun); /// : the exact plan the user confirmed. public sealed record ImportJobParameters(Guid ArchiveId, ImportPlan Plan, Guid? CardId, bool Verify, Guid? UserId); /// : no target; the newest copies are kept. public sealed record BackupParameters(int Keep); /// /// : target = the archive (or none); the clean-up steps to run, by name and in order, and /// the age in days from which what they clean goes (0 keeps everything). /// public sealed record CleanupParameters(IReadOnlyList Steps, int OlderThanDays); /// /// : target = the archive; the entries of the confirmed plan, each with its own fingerprint /// (), and the plan's fingerprint (). /// public sealed record EmptyTrashParameters(IReadOnlyList Entries, string Fingerprint); /// One entry of a confirmed emptying: its name and fingerprint when it was planned. public sealed record EmptyTrashItem(string Name, string Fingerprint); /// /// (Reorganize, owner review 2, R7): target = the archive; the templates (null keeps that part), /// the sequences the confirmed plan changes in the order it was made for, and the plan's fingerprint /// (, which pins every file rename by its digest). No file list: the job /// plans again and refuses when the plan is no longer the one confirmed. /// public sealed record MoveJobParameters(string? FolderTemplate, string? FileTemplate, string? TitleTemplate, IReadOnlyList Sequences, string Fingerprint); /// A sequence of a (a job queued by an earlier build also names a frames version, which is ignored). public sealed record MoveSequence(Guid Id); /// /// (owner review 2, R7): targets = the sequences converted, so the jobs that would touch them /// wait; the archive, the target format and JPEG quality, the mode chosen for this run, the sequences of the confirmed plan /// in its order, each with what it converts, and the plan's fingerprint (). A sequence /// whose photos to convert are no longer those confirmed is left as it is and reported. Which photos those are is not /// here but in the job's own file beside its journal (), so that the row stays as small as the /// number of sequences, whatever the number of photos, for everything that reads jobs. /// public sealed record ConvertJobParameters(Guid ArchiveId, ConvertTarget Target, int Quality, ConvertMode Mode, IReadOnlyList Sequences, string Fingerprint); /// /// A sequence of a : the frames version it was planned at, and the digest of the photos it /// converts, each with its content (). Under the sequence's lease, before it /// converts anything, the job takes the photos confirmed () from its plan made again and goes /// on only while they have that digest: photos that came in since (an upload while the job waited its turn) stay as they /// are, and a photo the plan did not list (one another program held while it was made) is never converted. Without the /// confirmed photos, the whole plan made again must have the digest. Null in a job an earlier build queued, which checks /// the frames version only. /// public sealed record ConvertSequence(Guid Id, int FramesVersion, string? Frames = null); /// /// A job ready to enqueue; , when set, is the id it is queued under (chosen first, for what the job /// reads beside its journal: ), otherwise the engine gives it one. /// public sealed record ArchiveJobRequest(JobKind Kind, IReadOnlyList Targets, string? Label, string? ParametersJson, JobPriority Priority, Guid? Id = null); [JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, UseStringEnumConverter = true)] [JsonSerializable(typeof(ScanParameters))] [JsonSerializable(typeof(VerifyParameters))] [JsonSerializable(typeof(ImageJobParameters))] [JsonSerializable(typeof(MaintenanceParameters))] [JsonSerializable(typeof(ImportJobParameters))] [JsonSerializable(typeof(BackupParameters))] [JsonSerializable(typeof(CleanupParameters))] [JsonSerializable(typeof(EmptyTrashParameters))] [JsonSerializable(typeof(MoveJobParameters))] [JsonSerializable(typeof(ConvertJobParameters))] [JsonSerializable(typeof(ConvertJournal))] [JsonSerializable(typeof(StagedLine))] [JsonSerializable(typeof(PinnedSequence))] [JsonSerializable(typeof(ConfirmedLine))] [JsonSerializable(typeof(CardProfile))] internal sealed partial class ArchiveJobJson : JsonSerializerContext { /// Parameters of a job, or when it has none. public static T Read(Job job, System.Text.Json.Serialization.Metadata.JsonTypeInfo typeInfo, T fallback) => job.ParametersJson is { Length: > 0 } json ? JsonSerializer.Deserialize(json, typeInfo) ?? fallback : fallback; }