using System.Collections.Generic;
using UnityEngine;
using YachtDice.Modifiers.Core;
using YachtDice.Modifiers.Runtime;

namespace YachtDice.Modifiers.Definition
{
    [CreateAssetMenu(fileName = "NewBehavior", menuName = "YachtDice/Modifiers/Behavior")]
    public class ModifierBehavior : ScriptableObject
    {
        [field: SerializeField] public TriggerType Trigger { get; private set; }
        [SerializeField] private List<Condition> conditions = new();
        [SerializeField] private List<Effect> effects = new();

        public IReadOnlyList<Condition> Conditions => conditions;
        public IReadOnlyList<Effect> Effects => effects;

        public bool EvaluateConditions(ModifierContext context, ModifierInstance instance)
        {
            for (int i = 0; i < conditions.Count; i++)
            {
                if (conditions[i] != null && !conditions[i].Evaluate(context, instance))
                    return false;
            }
            return true;
        }

#if UNITY_EDITOR
        public static ModifierBehavior CreateForTest(
            TriggerType trigger,
            List<Condition> conditions,
            List<Effect> effects)
        {
            var so = CreateInstance<ModifierBehavior>();
            so.Trigger = trigger;
            so.conditions = conditions ?? new List<Condition>();
            so.effects = effects ?? new List<Effect>();
            return so;
        }
#endif
    }
}
