using System;
using System.Collections.Generic;
namespace ytLive.Services;
///
/// TASK 32·1: how many times to relaunch the push, and how long to wait between tries.
/// Minimum waits, deliberately (creator ruling 2026-11-05): YouTube is not generous about
/// holding a broadcast whose ingest has gone quiet, so every second spent not pushing is grace spent.
/// The first attempt is immediate — there is nothing to wait for when the socket has just died.
/// Pure so the schedule is asserted without waiting on it.
///
public sealed class StreamRetryPolicy
{
/// Immediate, then +1 s, +2 s, +3 s — four attempts inside about six seconds.
public static readonly StreamRetryPolicy Default = new(new[]
{
TimeSpan.Zero,
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(2),
TimeSpan.FromSeconds(3),
});
public IReadOnlyList Waits { get; }
public StreamRetryPolicy(IReadOnlyList waits)
{
if (waits == null || waits.Count == 0)
throw new ArgumentException("A retry policy needs at least one attempt.", nameof(waits));
Waits = waits;
}
public int Attempts => Waits.Count;
/// The wait BEFORE (0-based).
public TimeSpan WaitBefore(int attemptIndex)
=> attemptIndex < 0 || attemptIndex >= Waits.Count ? TimeSpan.Zero : Waits[attemptIndex];
}