using System;
using System.Linq;
using Sirenix.OdinInspector.Editor.Validation;
using VOID.Editor.AttributeValidator.Objects;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;

[assembly: RegisterValidator(typeof(UnitObjectEquipmentValidator))]

namespace VOID.Editor.AttributeValidator.Objects
{
    public class UnitObjectEquipmentValidator : ValueValidator<UnitObjectEquipment>
    {
        protected override void Validate(ValidationResult result)
        {
            if (Value == null) return;
            
            AreValidWearablesPlaced(result);
        }

        private void AreValidWearablesPlaced(ValidationResult result)
        {
            foreach (var slotType in Enum.GetValues(typeof(EquipmentSlotType)).Cast<EquipmentSlotType>())
            {
                var wearable = Value.GetEquipped(slotType);
                if (wearable == null) return;
                
                // Wrong type of wearable placed in this slot
                if (Value.CanEquipInSlot(slotType, wearable) == false)
                    result.AddError($"<u><b>{wearable.name}</b></u> can't be placed in <u><b>{slotType}</b></u> slot!");
            }
        }
    }
}