using EscapeRoomEngine.Engine.Runtime.Utilities;
using JetBrains.Annotations;
using NaughtyAttributes;
using UnityEngine;

namespace Test_Assets
{
    /// <summary>
    /// This class is used to test the <see cref="Backtrack"/> struct.
    /// </summary>
    public class BacktrackingTest : MonoBehaviour
    {
        public int[] values;
        public int target;

        [Button]
        [UsedImplicitly]
        public void Closest()
        {
            PrintResult(Backtrack.Closest(new Range(0, values.Length).ToArray(), values, target));
        }

        [Button]
        [UsedImplicitly]
        public void ClosestLower()
        {
            var backtrack = new Backtrack(new Range(0, values.Length).ToArray(), values, target);
            PrintResult(backtrack.BruteForceLower());
        }

        [Button]
        [UsedImplicitly]
        public void ClosestHigher()
        {
            var backtrack = new Backtrack(new Range(0, values.Length).ToArray(), values, target);
            PrintResult(backtrack.BruteForceHigher());
        }

        private void PrintResult(int[] indices)
        {
            var sum = 0;
            foreach (var i in indices)
            {
                Debug.Log(values[i]);
                sum += values[i];
            }
            Debug.Log($"sum: {sum}");
        }
    }
}