using Chronos.Core.Imaging; namespace Chronos.Core.Model; /// A rooted folder tree that holds originals, sidecars, proxies and exports (BRIEF §7). public sealed record Archive { public required Guid Id { get; init; } public required string Name { get; init; } public required string RootPath { get; init; } public string FolderTemplate { get; init; } = Naming.TemplateDefaults.Folder; public string FileTemplate { get; init; } = Naming.TemplateDefaults.File; public int SchemaVersion { get; init; } = 1; public DateTimeOffset Created { get; init; } /// Proxy long edge in pixels; 0 = full size, -1 = proxies disabled. public int ProxyLongEdge { get; init; } = 1920; } /// /// The tombstone of a photo removed from a sequence (owner review 2, R6): its SHA-256, the replacement's when it was /// replaced by a converted file, why and when. Kept in the sidecar (removed) and the index (frame_removals), so /// sync never offers the photo back and an upload of that content into the sequence is answered as already there. /// public sealed record FrameRemoval(Guid SequenceId, string Sha256, string? ReplacementSha256, RemovalReason Reason, DateTimeOffset RemovedAt); /// One shoot: a folder of frames that becomes one project (BRIEF §5). public sealed record Sequence { public required Guid Id { get; init; } public required Guid ArchiveId { get; init; } public string? Title { get; init; } /// Folder relative to the archive root, forward slashes. public required string Folder { get; init; } public string? CameraMake { get; init; } public string? CameraModel { get; init; } public string? CameraSerial { get; init; } public string? Lens { get; init; } public DateTime? FirstCapture { get; init; } public DateTime? LastCapture { get; init; } public int FrameCount { get; init; } /// Median capture interval in seconds. public double? MedianInterval { get; init; } public long TotalBytes { get; init; } public SequenceStatus Status { get; init; } public int RenderedCount { get; init; } public DateTimeOffset? VerifiedAt { get; init; } public Guid? HeroFrameId { get; init; } public IReadOnlyList Tags { get; init; } = []; public int Rating { get; init; } public string? Notes { get; init; } /// Render settings ("project") as JSON. public string? SettingsJson { get; init; } /// Compact analysis summary as JSON; the full report lives in .chronos/analysis.json. public string? AnalysisJson { get; init; } public SequenceOrigin Origin { get; init; } public SyncState SyncState { get; init; } public int SettingsVersion { get; init; } public int FramesVersion { get; init; } public Guid? OwnerUserId { get; init; } public int WarningCount { get; init; } /// Frames that decode only through their embedded preview (, BRIEF §8.2). public int PreviewOnlyCount { get; init; } public DateTimeOffset UpdatedAt { get; init; } /// The title, else capture date and camera, else the folder name (never empty). public string DisplayTitle { get { if (!string.IsNullOrWhiteSpace(Title)) return Title; var described = $"{FirstCapture:yyyy-MM-dd} {CameraModel}".Trim(); if (described.Length > 0) return described; var folder = Folder.TrimEnd('/'); return folder.Length > 0 ? folder[(folder.LastIndexOf('/') + 1)..] : Id.ToString("N")[..8]; } } } /// One photo of a sequence. public sealed record Frame { public required Guid Id { get; init; } public required Guid SequenceId { get; init; } public required int Index { get; init; } /// Path relative to the archive root, forward slashes. public required string RelativePath { get; init; } public required string FileName { get; init; } public string? OriginalFileName { get; init; } public long Size { get; init; } /// Lower-case hex SHA-256 of the original file. public string? Sha256 { get; init; } /// Camera wall-clock time including sub-seconds (unspecified kind). public DateTime? CapturedAt { get; init; } /// UTC offset of when known, in minutes. public int? UtcOffsetMinutes { get; init; } public TimestampSource TimestampSource { get; init; } public double? ExposureTime { get; init; } public double? FNumber { get; init; } public int? Iso { get; init; } public double? FocalLength { get; init; } public double? ExposureBias { get; init; } public int? WhiteBalance { get; init; } public int Orientation { get; init; } = 1; public int Width { get; init; } public int Height { get; init; } public ImageFileFormat Format { get; init; } public long? PreviewOffset { get; init; } public long? PreviewLength { get; init; } /// Size of the largest embedded preview like and (before orientation); /// 0 when there is none or it is not known. public int PreviewWidth { get; init; } public int PreviewHeight { get; init; } /// Mean log2 luminance once analysed. public double? MeanLogLuminance { get; init; } public double? ClipLow { get; init; } public double? ClipHigh { get; init; } public FrameFlags Flags { get; init; } /// Exposure value at ISO 100: log2(N²/t) − log2(ISO/100). public double? ExposureValue => ExposureTime is > 0 && FNumber is > 0 ? Math.Log2(FNumber.Value * FNumber.Value / ExposureTime.Value) - Math.Log2((Iso ?? 100) / 100.0) : null; } /// An exported video or image sequence. public sealed record Render { public required Guid Id { get; init; } public required Guid SequenceId { get; init; } public required string PresetName { get; init; } public string? SettingsJson { get; init; } public required string OutputPath { get; init; } public string? Codec { get; init; } public int Width { get; init; } public int Height { get; init; } public double Fps { get; init; } public double DurationSeconds { get; init; } public long Bytes { get; init; } public DateTimeOffset Created { get; init; } public string? ProducedBy { get; init; } /// The project whose version was rendered (owner review 2, R8); null for a render of the sequence's settings. public Guid? ProjectId { get; init; } /// The project version rendered; null for a render of the sequence's settings. public Guid? ProjectVersionId { get; init; } /// /// Lower-case hex SHA-256 of a single-file render (owner review 1, R9), hashed when it is recorded; null for an image /// sequence's folder (verified file by file when copied) and for a render recorded before migration 0010, hashed the /// first time it is copied, deleted or restored. /// public string? Sha256 { get; init; } /// /// What the render is beyond its codec (): null for a video or an image sequence (told apart by /// ), for one frame saved as an image. A text, so a newer Chronos can add /// kinds. /// public string? Kind { get; init; } } /// The values of and of the videos library's kinds (owner review 1, R9). public static class RenderKind { /// A video file (MP4, AVI, GIF, APNG): null and a video codec. public const string Video = "video"; /// A folder of numbered images: null and an image-sequence codec. public const string Sequence = "sequence"; /// One frame saved as one image ("Save frame"): fps 0 and duration 0. public const string Still = "still"; /// /// The library kind of a render: its when set (a kind of a newer Chronos as it is), else /// for an image-sequence codec and otherwise. /// public static string Of(string? kind, string? codec) => kind is { Length: > 0 } ? kind : codec is { } c && c.EndsWith("sequence", StringComparison.OrdinalIgnoreCase) ? Sequence : Video; /// /// , telling a still apart when its kind was lost (one uploaded to a server of before /// phase 5, which does not record it): an image-sequence codec with fps 0 and duration 0, which every still records and /// no image sequence has. /// public static string Of(string? kind, string? codec, double fps, double durationSeconds) { var of = Of(kind, codec); return of == Sequence && fps <= 0 && durationSeconds <= 0 ? Still : of; } /// public static string Of(Render render) { ArgumentNullException.ThrowIfNull(render); return Of(render.Kind, render.Codec, render.Fps, render.DurationSeconds); } } /// /// A verified copy of a render in a videos folder (owner review 1, R9; render_copies): recorded once the copy matched /// its render. There is no link to renders, so the copy of a server render downloaded to a PC is recorded too, and a /// copy outlives its render's deletion (copies are the user's files; Chronos never deletes them). /// public sealed record RenderCopy { public required Guid Id { get; init; } /// The render copied (of this index, or of the server it was downloaded from). public required Guid RenderId { get; init; } /// Absolute path of the copy (a file, or a folder for an image sequence). public required string Path { get; init; } /// Lower-case hex SHA-256 the copy was verified against; null for an image sequence's folder (verified per file). public string? Sha256 { get; init; } public long Bytes { get; init; } public DateTimeOffset CopiedAt { get; init; } /// The user (server) or the PC (desktop) that copied it. public string? CopiedBy { get; init; } } /// /// A project of a sequence (owner review 2, R8): a named set of render settings ("4K landscape", "Vertical social") with a /// linear history of versions. Every sequence has one Main project, whose head is the sequence's own settings /// (). Its sidecar (.chronos/projects/<id>/project.json) is the truth; the /// index row is derived. /// public sealed record SequenceProject { public required Guid Id { get; init; } public required Guid SequenceId { get; init; } public required string Name { get; init; } /// The sequence's Main project: its head is mirrored into the sequence's settings and drives its hero frame. public bool IsMain { get; init; } /// The newest version; null before the first. public Guid? HeadVersionId { get; init; } /// The newest version's number (1, 2, …); 0 before the first. public int HeadNumber { get; init; } /// Main only: the sequence's settings version its head was last mirrored to or taken from. public int? MirroredSettingsVersion { get; init; } /// /// Main only: the version last mirrored to or taken from the sequence's settings; another than the head while a mirror /// is to complete (a push a crash cut short), null when unknown (an index rebuilt from the sidecars). /// public Guid? MirroredVersionId { get; init; } public string? CreatedBy { get; init; } public DateTimeOffset CreatedAt { get; init; } public DateTimeOffset UpdatedAt { get; init; } /// When the project was deleted (its folder moved to .chronos/projects/.trash); null while it exists. public DateTimeOffset? DeletedAt { get; init; } } /// How a project version came to be (stored as its wire name, ). public enum ProjectVersionKind { /// Saved by a user in a workspace. Commit, /// A working state merged with versions stored meanwhile. Merge, /// An earlier version brought back (). Restore, /// The first version of a project made from settings that were there (Main from the sequence's settings, a copy of another project). Imported, /// Main only: settings written by a path outside the projects (an analysis, the server's API, an older Chronos). External, } /// Wire names of : commit, merge, restore, imported, external. public static class ProjectVersionKinds { public static string Name(ProjectVersionKind kind) => kind.ToString().ToLowerInvariant(); /// The kind a wire name stands for; for one this build does not know. public static ProjectVersionKind Parse(string? name) { foreach (var kind in Enum.GetValues()) { if (string.Equals(Name(kind), name, StringComparison.OrdinalIgnoreCase)) return kind; } return ProjectVersionKind.Commit; } } /// /// One version of a project (owner review 2, R8): immutable once stored. is the portable form /// of the settings (frame positions parked by photo, ProjectContent) and the SHA-256 of /// its UTF-8 bytes, checked wherever it is stored or read. /// public sealed record ProjectVersion { public required Guid Id { get; init; } public required Guid ProjectId { get; init; } /// The version it was made from; null for a project's first. public Guid? ParentId { get; init; } /// 1 for the first version of a project, then one more for each. public required int Number { get; init; } public ProjectVersionKind Kind { get; init; } public string? Author { get; init; } /// The PC it was made on ("STUDIO-PC" from a workspace; the archive's own versions carry its lease owner, "chronos@STUDIO-PC"). public string? ClientName { get; init; } public string? Note { get; init; } public required string SettingsJson { get; init; } public required string ContentHash { get; init; } /// The settings format (ProjectSettings.Version) of ; a newer one opens read-only. public int SettingsFormat { get; init; } = 1; /// The frames version of the sequence the settings were made against. public int FramesVersion { get; init; } /// For a : the version brought back. public Guid? RestoredFrom { get; init; } /// When it was made (in a workspace). public DateTimeOffset CreatedAt { get; init; } /// When its home stored it; null for a workspace's version not pushed yet. public DateTimeOffset? StoredAt { get; init; } } /// Any long operation: resumable, cancellable, logged (BRIEF §5, §14.6). public sealed record Job { public required Guid Id { get; init; } public required JobKind Kind { get; init; } public IReadOnlyList TargetIds { get; init; } = []; /// Human-readable target ("Harbour sunset", "Archive · 2024"). public string? TargetLabel { get; init; } public string? ParametersJson { get; init; } public JobState State { get; init; } public JobPriority Priority { get; init; } = JobPriority.Normal; public long ProgressDone { get; init; } public long ProgressTotal { get; init; } public double? ItemsPerSecond { get; init; } public TimeSpan? Eta { get; init; } /// Opaque resume cursor written at checkpoints. public string? Checkpoint { get; init; } public string? LogTail { get; init; } public Guid? CreatedBy { get; init; } public string? NodeId { get; init; } public int Attempts { get; init; } public string? Error { get; init; } public DateTimeOffset Created { get; init; } public DateTimeOffset? Started { get; init; } public DateTimeOffset? Finished { get; init; } /// The schedule that queued this job; null for jobs queued by a user or by other jobs (owner review 2, R10). public Guid? ScheduleId { get; init; } /// /// What the job did when its progress was last saved (step, item, photo x of y, part n of m); null when its handler /// reports none or the job never ran. Kept when the job stops, so a paused or failed one tells where it stopped. /// public JobDetail? Detail { get; init; } } /// /// A recurring job (owner review 2, R10): an action (scan, verify, backup, …) with its parameters, run on a recurrence /// in the host's time zone. System schedules ( set) stand for the timers a host used to run out of /// sight; they are seeded once, can be edited and reset, never deleted. /// public sealed record Schedule { public required Guid Id { get; init; } /// Stable key of a host's system schedule (archive-scan); null for schedules a user created. public string? SystemKey { get; init; } public required string Name { get; init; } /// Wire name of the action (scan, verify, backup…). public required string Action { get; init; } /// What the action works on: current, the host's archive. public string Target { get; init; } = "current"; /// The action's parameters as JSON (camelCase, only the fields the action reads). public string? ParametersJson { get; init; } /// The recurrence in its text form (every:10m, daily:03:00, weekly:mon,thu@02:30, monthly:1@04:00). public required string Recurrence { get; init; } /// A run missed while the host was off happens once when it comes back; otherwise it is skipped. public bool CatchUp { get; init; } = true; /// Priority of the jobs it queues. public JobPriority Priority { get; init; } = JobPriority.Background; public bool Enabled { get; init; } = true; /// When it fires next (UTC); null while disabled or not computed yet. public DateTimeOffset? NextRun { get; init; } public DateTimeOffset? LastRun { get; init; } /// The first job the last run queued. public Guid? LastJobId { get; init; } /// What the last run did: queued, skipped-pending, skipped-offline, skipped-nothing, /// unavailable or failed:<reason>. public string? LastOutcome { get; init; } public Guid? CreatedBy { get; init; } public DateTimeOffset Created { get; init; } public DateTimeOffset Updated { get; init; } /// True for a host's system schedule. public bool IsSystem => SystemKey is not null; } /// A memory card known to this client (BRIEF §13). public sealed record MediaCard { public required Guid Id { get; init; } /// {volumeSerial}-{label}-{capacity}. public required string Identity { get; init; } public uint VolumeSerial { get; init; } public string? Label { get; init; } public long Capacity { get; init; } public string? Nickname { get; init; } public string? CameraMake { get; init; } public string? CameraModel { get; init; } public string? CameraSerial { get; init; } public string? ProfileJson { get; init; } public bool AutoImport { get; init; } public DateTimeOffset FirstSeen { get; init; } public DateTimeOffset LastSeen { get; init; } } public sealed record User { public required Guid Id { get; init; } public required string Username { get; init; } public string? DisplayName { get; init; } public required string PasswordHash { get; init; } public UserRole Role { get; init; } public Permissions Permissions { get; init; } public long QuotaBytes { get; init; } public long UsedBytes { get; init; } public bool Disabled { get; init; } public bool MustChangePassword { get; init; } public DateTimeOffset Created { get; init; } public DateTimeOffset? LastLogin { get; init; } } public sealed record SessionToken { public required string TokenHash { get; init; } public required Guid UserId { get; init; } public string? ClientName { get; init; } public DateTimeOffset Created { get; init; } public DateTimeOffset Expires { get; init; } public DateTimeOffset LastUsed { get; init; } public bool Revoked { get; init; } } public sealed record RenderNode { public required Guid Id { get; init; } public required Guid UserId { get; init; } public required string ClientName { get; init; } public string? CapabilitiesJson { get; init; } public DateTimeOffset LastHeartbeat { get; init; } public string State { get; init; } = "idle"; } public sealed record AuditEntry { public required Guid Id { get; init; } public DateTimeOffset At { get; init; } public Guid? UserId { get; init; } public string? Username { get; init; } public required string Action { get; init; } public string? TargetKind { get; init; } public string? TargetId { get; init; } public string? Details { get; init; } public string? RemoteAddress { get; init; } }