using System;
namespace ytLive.Services;
///
/// TASK 55ยท3: a recording that dies of a full disk is a trust breach, not a support ticket. The guard is
/// a pure threshold policy so the numbers are visible in one place and testable without a drive.
///
/// Thresholds chosen 2026-11-10 for a 1080p stream at 8 Mbps (~3.6 GB/hour): refusing to start
/// under 1 GB keeps the creator from beginning something that cannot finish; a warning under
/// 5 GB says "you have about eighty minutes" while there is still time to act; and one mid-show
/// warning at 2 GB is the last useful moment before the encoder fails for a reason it will not
/// explain.
///
public static class DiskSpaceGuard
{
public const long BlockStartBytes = 1L * 1024 * 1024 * 1024;
public const long WarnStartBytes = 5L * 1024 * 1024 * 1024;
public const long WarnDuringBytes = 2L * 1024 * 1024 * 1024;
public enum StartDecision
{
Ok,
Warn,
Block,
}
public static StartDecision ForStart(long freeBytes)
=> freeBytes < BlockStartBytes ? StartDecision.Block
: freeBytes < WarnStartBytes ? StartDecision.Warn
: StartDecision.Ok;
/// One warning per session, once the drive falls below the mid-recording threshold.
public static bool ShouldWarnDuring(long freeBytes) => freeBytes < WarnDuringBytes;
/// Free bytes on the drive that holds , or null when it cannot be
/// read (a removable drive that just went away must not block a recording that is already running).
public static long? FreeBytes(string folder)
{
try
{
var root = System.IO.Path.GetPathRoot(System.IO.Path.GetFullPath(folder));
if (string.IsNullOrEmpty(root)) return null;
return new System.IO.DriveInfo(root).AvailableFreeSpace;
}
catch
{
return null;
}
}
}