using PSLauncher.Models;

namespace PSLauncher.App.ViewModels;

public sealed class InstalledVersionViewModel
{
    public InstalledVersion Model { get; }

    public InstalledVersionViewModel(InstalledVersion model) => Model = model;

    public string Display => $"v{Model.Version}";

    public string Subtitle =>
        $"{FormatSize(Model.SizeBytes)} • Installée le {Model.InstalledAt.ToLocalTime():dd/MM/yyyy}";

    private static string FormatSize(long bytes)
    {
        if (bytes <= 0) return "—";
        string[] units = { "o", "Ko", "Mo", "Go", "To" };
        double v = bytes;
        int u = 0;
        while (v >= 1024 && u < units.Length - 1) { v /= 1024; u++; }
        return $"{v:0.#} {units[u]}";
    }

    public override string ToString() => Display;
}
