using System.Reflection;
using Godot;
using ADEPT.Core;
using ADEPT.Core.Cogwheel;
using Cogwheel;


namespace ADEPT.Core;

public partial class Main : Node
{
    private static CommandsManager _commandsManager;
    private static GodotCogwheelConsole _cogwheelConsole;
    
    public CanvasLayer MainCanvas { get; private set; }
    
    public override void _Ready()
    {
        MainCanvas = GetNode<CanvasLayer>("MainCanvas");
        
        ADEPT.Initialize(this);
        
        _commandsManager = new CommandsManager();
        _cogwheelConsole = MainCanvas.GetNode<GodotCogwheelConsole>("CogwheelConsole");
        if (_cogwheelConsole is null) throw new System.Exception("CogwheelConsole not found in MainNode.");
        
        _commandsManager.AddAssembly(Assembly.GetExecutingAssembly());
        _commandsManager.AddAssembly(Assembly.GetAssembly(typeof(CommandsManager)));
        
        COGWHEEL.Initialize(_commandsManager, _cogwheelConsole);
        COGWHEEL.RegisterObject(this);
        
        _cogwheelConsole.LogInfo("COGWHEEL " + " initialized.");
        _cogwheelConsole.LogInfo("ADEPT " + ADEPT.Constants.Version + " initialized.");
        _cogwheelConsole.LogInfo("Type 'list' for a list of commands.");
        
    }

    [Command(Name = "test", Description = "Test command.")]
    private void Test()
    {
        COGWHEEL.LogWarning("Testing!\nTesting!\nTesting!");
    }
}