#nullable enable


namespace TagFighter.Effects.Steps
{
    using System.Collections.Generic;
    using System.Linq;

    [StepType(StepTypeAttribute.ReleaseStep)]
    public class ReleaseWeave : ReleaseStep
    {

        public override IEnumerable<IPort> Inputs {
            get {
                return Enumerable.Empty<IPort>();
            }
        }

        public override bool IsValid => true;

        public override string ToString() => "Release Weave";

        public override void Run(EffectInput blackBoard) {
            var appliedResource = blackBoard.Context.GetAllResourcesInRegister<ResourceLocationAccessors.ContextRegisters.Current>();

            blackBoard.Context.EffectSystem.ApplyTagsEffect(appliedResource, blackBoard.Context.Caster, blackBoard.Context.EffectLocation, blackBoard.Context.AreaOfEffect);


            blackBoard.Affected = blackBoard.Context.GetAffectedUnits().ToList();
            foreach (var effect in blackBoard.Context.EffectStepsToTrigger) {
                effect.Run(blackBoard);
            }
            blackBoard.Context.EffectStepsToTrigger.Clear();
        }
    }

}