using System.Collections.Generic;
using YachtDice.Modifiers.Definition;

namespace YachtDice.Modifiers.Runtime
{
    public class ModifierInstance
    {
        public ModifierDefinition Definition { get; }
        public bool IsActive { get; set; }
        public int RemainingUses { get; set; }
        public int Stacks { get; set; } = 1;
        public Dictionary<string, float> CustomState { get; } = new();

        public bool IsExpired => Definition.HasLimitedUses && RemainingUses <= 0;

        public ModifierInstance(ModifierDefinition definition)
        {
            Definition = definition;
            RemainingUses = definition.HasLimitedUses ? definition.MaxUses : -1;
        }

        public void ConsumeCharge(int amount = 1)
        {
            if (!Definition.HasLimitedUses) return;
            RemainingUses -= amount;
            if (RemainingUses < 0) RemainingUses = 0;
        }
    }
}
