using System.Collections.Generic;
using System.Linq;
using EscapeRoomEngine.Engine.Runtime.Modules;
using UnityEngine;

namespace EscapeRoomEngine.Engine.Runtime.Requirements
{
    /// <summary>
    /// A generic requirement class that defines how requirements filter candidates.
    /// </summary>
    public abstract class Requirement<T> : ScriptableObject
    {
        protected abstract List<T> FilterCandidates(List<T> candidates, Module module, Space space);

        protected static List<T> Candidates(
            List<T> candidates,
            IEnumerable<Requirement<T>> requirements,
            Module module, Space space)
        {
            return requirements.Aggregate(candidates,
                (current, requirement) => requirement.FilterCandidates(current, module, space));
        }
    }
}