using System.Text.Json;
using System.Text.Json.Serialization;
using Titano.Core.Naming;
namespace Titano.Core.Archiving;
///
/// .titano/archive.json at the archive root (BRIEF §7). Fields this build does not know are kept in
/// and written back unchanged.
///
public sealed record ArchiveManifest
{
public const int CurrentSchemaVersion = 1;
public int SchemaVersion { get; init; } = CurrentSchemaVersion;
public required Guid Id { get; init; }
public required string Name { get; init; }
public DateTimeOffset Created { get; init; }
public LayoutTemplates LayoutTemplates { get; init; } = new();
public ProxyPolicy ProxyPolicy { get; init; } = new();
///
/// The default policy when absent: archives written before it existed have none, and the source-generated reader
/// sets an init-only property it does not find to null rather than keeping its initializer.
///
public ThumbnailPolicy ThumbnailPolicy
{
get => _thumbnailPolicy;
init => _thumbnailPolicy = value ?? new ThumbnailPolicy();
}
[JsonExtensionData]
public Dictionary? Extra { get; set; }
private readonly ThumbnailPolicy _thumbnailPolicy = new();
}
/// Naming templates used when frames enter the archive (BRIEF §7.1).
public sealed record LayoutTemplates
{
public string Folder { get; init; } = TemplateDefaults.Folder;
public string File { get; init; } = TemplateDefaults.File;
[JsonExtensionData]
public Dictionary? Extra { get; set; }
}
/// Proxy generation policy (BRIEF §8.5).
public sealed record ProxyPolicy
{
public const int Disabled = -1;
public const int FullSize = 0;
/// Long edge in pixels: 1280, 1920 (default) or 2560; or .
public int LongEdge { get; init; } = 1920;
public int Quality { get; init; } = 92;
[JsonExtensionData]
public Dictionary? Extra { get; set; }
/// True for the long edges an archive accepts: disabled, full size, or 256 to 8192 px.
public static bool IsValidLongEdge(int longEdge) => longEdge is Disabled or FullSize or (>= 256 and <= 8192);
}
/// Thumbnail policy (BRIEF §8.5): long edge and JPEG quality of the thumbnails packed per sequence.
public sealed record ThumbnailPolicy
{
public const int MinLongEdge = 160;
public const int MaxLongEdge = 1024;
///
/// Long edge in pixels (320 by default); thumbnails built before a change keep their size until rebuilt. A value the
/// file lacks (read as 0) is the default.
///
public int LongEdge
{
get => _longEdge;
init => _longEdge = value > 0 ? value : FrameImageRenderer.ThumbnailLongEdge;
}
/// JPEG quality (80 by default); a value the file lacks (read as 0) or out of 1–100 is the default.
public int Quality
{
get => _quality;
init => _quality = value is > 0 and <= 100 ? value : FrameImageRenderer.ThumbnailQuality;
}
[JsonExtensionData]
public Dictionary? Extra { get; set; }
private readonly int _longEdge = FrameImageRenderer.ThumbnailLongEdge;
private readonly int _quality = FrameImageRenderer.ThumbnailQuality;
public static bool IsValidLongEdge(int longEdge) => longEdge is >= MinLongEdge and <= MaxLongEdge;
}