using PLib.Application.Library;
namespace PLib.Desktop.Settings;
///
/// The subset of configuration the user can change at runtime, as one snapshot.
///
///
/// Everything is written in a single pass rather than key by key: a settings file that is
/// only ever replaced whole cannot end up in a state that never existed in the UI.
///
public sealed record AppSettings
{
public required IReadOnlyList Folders { get; init; }
public required int ThumbnailWidth { get; init; }
public required double ThumbnailPositionRatio { get; init; }
public required int MaxIndexingConcurrency { get; init; }
public required long MinimumFileSizeInBytes { get; init; }
public required ThemeMode Theme { get; init; }
public required double Volume { get; init; }
public required bool IsMuted { get; init; }
public static AppSettings From(
LibraryOptions library,
AppearanceOptions appearance,
PlaybackOptions playback) => new()
{
Folders = [.. library.Folders],
ThumbnailWidth = library.ThumbnailWidth,
ThumbnailPositionRatio = library.ThumbnailPositionRatio,
MaxIndexingConcurrency = library.MaxIndexingConcurrency,
MinimumFileSizeInBytes = library.MinimumFileSizeInBytes,
Theme = appearance.Theme,
Volume = playback.Volume,
IsMuted = playback.IsMuted,
};
///
/// True when the difference between the two snapshots means the library has to be
/// walked again. Cosmetic changes must not trigger a rescan.
///
public bool RequiresRescanComparedTo(AppSettings other) =>
!Folders.SequenceEqual(other.Folders, LibraryPathComparer.Instance) ||
MinimumFileSizeInBytes != other.MinimumFileSizeInBytes;
}