using Beam.Models;

namespace Beam.Downloaders;

public class SkipPredicateOptions<OutType> {
    public required SkipPredicate<OutType>?[]? SkipPredicates { get; init; }
    public bool ProcessInParallel { get; init; } = false;
    public int? ParallelThreads { get; init; }
}

public class SkipPredicateOptionsBuilder<OutType> {
    private List<SkipPredicate<OutType>?> _skipPredicates { get; set; } = [];
    private bool _processInParallel { get; set; } = false;
    private int? _parallelThreads { get; set; }

    public SkipPredicateOptionsBuilder<OutType> WithSkipPredicate(SkipPredicate<OutType> predicate, bool replace=false) {
        if (replace)
            _skipPredicates.Clear();
        _skipPredicates.Add(predicate);
        return this;
    }

    public SkipPredicateOptionsBuilder<OutType> WithSkipPredicates(SkipPredicate<OutType>[] predicates,
        bool replace = true) {
        if (replace)
            _skipPredicates.Clear();
        _skipPredicates.AddRange(predicates);
        return this;
    }

    public SkipPredicateOptionsBuilder<OutType> ProcessInParallel(bool processInParallel = true) {
        _processInParallel = processInParallel;
        return this;
    }

    public SkipPredicateOptionsBuilder<OutType> WithParallelThreads(int parallelThreads) {
        _parallelThreads = parallelThreads;
        return this;
    }

    public SkipPredicateOptions<OutType> Build() {
        return new SkipPredicateOptions<OutType>() {
            SkipPredicates = _skipPredicates.ToArray(),
            ParallelThreads = _parallelThreads,
            ProcessInParallel = _processInParallel
        };
    }
}