using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;

namespace RebootKit.Engine.Simulation.Interactors {
    public interface IInteractorAsync<in TInteractable> {
        UniTask Interact(TInteractable target, CancellationToken cancellationToken);
    }

    public interface IInteractor<in TInteractable> {
        void Interact(TInteractable target);
    }

    public class GroupInteractor<TInteractable> : IInteractor<TInteractable> {
        readonly List<IInteractor<TInteractable>> m_Interactors = new List<IInteractor<TInteractable>>();

        public void Interact(TInteractable target) {
            foreach (IInteractor<TInteractable> interactor in m_Interactors) interactor.Interact(target);
        }

        public void Add(IInteractor<TInteractable> interactor) {
            m_Interactors.Add(interactor);
        }

        public void Remove(IInteractor<TInteractable> interactor) {
            m_Interactors.Remove(interactor);
        }

        public void RemoveAll() {
            m_Interactors.Clear();
        }
    }
}