using Assets.Source.Core.Interfaces;
using UnityEngine;

namespace Assets.Source.Core.LevelDesign
{
    public static class DesignUtils
    {
        public static bool ValidationEnabled = true;

        public static void Validate(GameObject go, object target, bool checkValidationAbility = true)
        {
            if (checkValidationAbility && !ValidationEnabled)
                return;
            if (target == null)
                return;
            var type = target.GetType();
            foreach (var fieldInfo in type.GetFields())
            {
                if (typeof(IGOValidatable).IsAssignableFrom(fieldInfo.FieldType))
                {
                    var validatable = (IGOValidatable) fieldInfo.GetValue(target);
                    validatable.Validate(go);
                }
            }
        }
    }
}
