using UnityEngine;
using YachtDice.Modifiers.Core;
using YachtDice.Modifiers.Definition;
using YachtDice.Modifiers.Runtime;

namespace YachtDice.Modifiers.Conditions
{
    [CreateAssetMenu(fileName = "DieValueCondition", menuName = "YachtDice/Modifiers/Conditions/Die Value")]
    public class DieValueCondition : Condition
    {
        [SerializeField, Range(1, 6)] private int targetValue = 1;
        [SerializeField] private int minCount = 1;

        public override bool Evaluate(ModifierContext context, ModifierInstance instance)
        {
            if (context.DiceValues == null) return false;

            int count = 0;
            for (int i = 0; i < context.DiceValues.Length; i++)
            {
                if (context.DiceValues[i] == targetValue)
                    count++;
            }
            return count >= minCount;
        }

#if UNITY_EDITOR
        public static DieValueCondition CreateForTest(int targetValue, int minCount = 1)
        {
            var so = CreateInstance<DieValueCondition>();
            so.targetValue = targetValue;
            so.minCount = minCount;
            return so;
        }
#endif
    }
}
