namespace Mlaumcherb.Client.Avalonia.сеть;

public record struct DataSize(long Bytes)
{
    static string BytesToHumanReadable(long bytes)
    {
        long K = bytes / 1024;
        if (K == 0)
            return $"{bytes}b";
        float M = K / 1024f;
        if (M < 1)
            return $"{K:N1}Kb";
        float G = M / 1024f;
        if (G < 1)
            return $"{M:N1}Mb";
        return $"{G:N1}Gb";
    }

    public override string ToString() => BytesToHumanReadable(Bytes);
    
    public static implicit operator DataSize(long bytes) => new DataSize(bytes);
}

