using System.Collections.Generic;
using System.Linq;
using TagFighter.Effects;
using TagFighter.Effects.Steps;
using UnityEngine;

[CreateAssetMenu(fileName = "Rune", menuName = "Game/Combat/Rune")]

public class RuneRef : ScriptableObject
{
    public Sprite RuneSprite;

    [UnityEngine.Serialization.FormerlySerializedAs("rune")]
    public Rune Rune;

    public List<RuneEffect> RuneEffects = new();

    public void Cast(EffectContext context) {
        foreach (var runeEffect in RuneEffects) {
            var blackBoard = new EffectInput(context, Enumerable.Empty<Transform>(), TagFighter.Resources.StatModifierAccessor.Permanent);
            var root = runeEffect.Nodes.Where(effectStep => effectStep is ReleaseStep).FirstOrDefault() as ReleaseStep;
            if (root == null) {
                UnityEngine.Debug.Log("No Root Step For Effect");
            }
            else {
                root.Run(blackBoard);
            }

        }
    }

    public static implicit operator Rune(RuneRef runeRef) => runeRef.Rune;
}