using Beam.Models; namespace Beam.Downloaders; public sealed class FailurePredicateOptionsBuilder { private readonly System.Collections.Generic.List?> _predicates = new System.Collections.Generic.List?>(); private bool _processInParallel = false; private int? _parallelThreads = null; public FailurePredicateOptionsBuilder WithPredicate(AsyncDownloadFailurePredicate? predicate) { _predicates.Add(predicate); return this; } public FailurePredicateOptionsBuilder WithPredicates(System.Collections.Generic.IEnumerable?> predicates) { if (predicates == null) throw new System.ArgumentNullException(nameof(predicates)); _predicates.AddRange(predicates); return this; } public FailurePredicateOptionsBuilder WithPredicates(params AsyncDownloadFailurePredicate?[] predicates) { _predicates.Clear(); if (predicates != null) _predicates.AddRange(predicates); return this; } public FailurePredicateOptionsBuilder WithProcessInParallel(bool value = true) { _processInParallel = value; return this; } public FailurePredicateOptionsBuilder WithParallelThreads(int? threads) { if (threads.HasValue && threads.Value <= 0) throw new System.ArgumentOutOfRangeException(nameof(threads)); _parallelThreads = threads; return this; } public FailurePredicateOptions Build() { var arr = _predicates.Count == 0 ? [] : _predicates.ToArray(); return new FailurePredicateOptions { AsyncDownloadFailurePredicates = arr, ProcessInParallel = _processInParallel, ParallelThreads = _parallelThreads }; } }