using Unity.VisualScripting;
using UnityEngine;

namespace BansheeGz.BGDatabase
{
    [UnitCategory("BansheeGz")]

    public class LoadGameFromArray : SaveLoadA
    {
        
        [DoNotSerialize] public ControlInput _in;
        [DoNotSerialize] public ControlOutput _out;

        [DoNotSerialize] public ValueInput databaseContent;
        
        protected override void Definition()
        {
            _in = ControlInput("_in", Enter);
            _out = ControlOutput("_out");
            Succession(_in, _out);

            databaseContent = ValueInput<byte[]>("Database content");
            base.Definition();
        }

        private ControlOutput Enter(Flow flow)
        {
            var content = flow.GetValue<byte[]>(databaseContent);
            if (content == null)
            {
                Log(flow, "Unable to load database- content is null");
            }
            else
            {
                BGRepo.I.Addons.Get<BGAddonSaveLoad>().Load(content);
            }
            return _out;
        }
    }
}