using UnityEngine;
using Wacs.Core.Runtime;

namespace KitsuneCafe.Scripting
{
    public class ScriptRunner : MonoBehaviour
    {
        [SerializeField]
        private Runtime runtime;

        private RuntimeInstance instance;

        private void Start()
        {
            instance = runtime.Instantiate();

            var options = new InvokerOptions
            {
                LogGas = false,
                LogProgressEvery = 0,
                LogInstructionExecution = InstructionLogging.None,
                CalculateLineNumbers = false,
                CollectStats = StatsDetail.None,
            };

            var result = instance.Invoke<Value>(("hello", "main"), options);

            Debug.Log(result);

            if (instance.State.TryGetValue(SayCBinding.SayCBindingPath, out var state))
            {
                var fs = (SayCBinding.State)state;
                Debug.Log(fs.Output.ToString());
            }
        }
    }
}
