namespace StellaOps.Feedser.Source.Common.Cursors;

/// <summary>
/// Configuration applied when advancing sliding time-window cursors.
/// </summary>
public sealed class TimeWindowCursorOptions
{
    public TimeSpan WindowSize { get; init; } = TimeSpan.FromHours(4);

    public TimeSpan Overlap { get; init; } = TimeSpan.FromMinutes(5);

    public TimeSpan InitialBackfill { get; init; } = TimeSpan.FromDays(7);

    public TimeSpan MinimumWindowSize { get; init; } = TimeSpan.FromMinutes(1);

    public void EnsureValid()
    {
        if (WindowSize <= TimeSpan.Zero)
        {
            throw new InvalidOperationException("Window size must be positive.");
        }

        if (Overlap < TimeSpan.Zero)
        {
            throw new InvalidOperationException("Window overlap cannot be negative.");
        }

        if (Overlap >= WindowSize)
        {
            throw new InvalidOperationException("Window overlap must be less than the window size.");
        }

        if (InitialBackfill <= TimeSpan.Zero)
        {
            throw new InvalidOperationException("Initial backfill must be positive.");
        }

        if (MinimumWindowSize <= TimeSpan.Zero)
        {
            throw new InvalidOperationException("Minimum window size must be positive.");
        }
    }
}
