namespace AppTunnel.Models;
///
/// Represents a single connection history entry.
///
public class ConnectionHistoryEntry
{
public string Id { get; set; } = Guid.NewGuid().ToString("N")[..8];
/// Profile name at the time of connection.
public string ProfileName { get; set; } = "";
/// Server address.
public string ServerAddress { get; set; } = "";
/// When connection started.
public DateTime ConnectedAt { get; set; }
/// When connection ended.
public DateTime DisconnectedAt { get; set; }
/// Total duration of connection.
public TimeSpan Duration => DisconnectedAt - ConnectedAt;
/// Total bytes sent through tunnel.
public long BytesSent { get; set; }
/// Total bytes received through tunnel.
public long BytesReceived { get; set; }
/// Total data usage (sent + received).
public long TotalBytes => BytesSent + BytesReceived;
/// Formatted duration string.
public string DurationText
{
get
{
var d = Duration;
if (d.TotalHours >= 1)
return $"{(int)d.TotalHours}:{d.Minutes:D2}:{d.Seconds:D2}";
return $"{d.Minutes:D2}:{d.Seconds:D2}";
}
}
/// Formatted date/time string (Persian-friendly).
public string ConnectedAtText => ConnectedAt.ToString("yyyy/MM/dd HH:mm");
/// Formatted total data usage.
public string TotalDataText => FormatBytes(TotalBytes);
/// Formatted sent data.
public string SentText => FormatBytes(BytesSent);
/// Formatted received data.
public string ReceivedText => FormatBytes(BytesReceived);
private static string FormatBytes(long bytes)
{
if (bytes < 1024) return $"{bytes} B";
if (bytes < 1024 * 1024) return $"{bytes / 1024.0:F1} KB";
if (bytes < 1024 * 1024 * 1024) return $"{bytes / (1024.0 * 1024.0):F2} MB";
return $"{bytes / (1024.0 * 1024.0 * 1024.0):F2} GB";
}
}