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


namespace ADEPT.Core;

public partial class Main : Node
{
    private static CommandsManager _commandsManager;
    private static GodotCogwheelConsole _cogwheelConsole;
    private static LessonHandler _lessonHandler;
    
    public CanvasLayer MainCanvas { get; private set; }
    
    public override void _Ready()
    {
        MainCanvas = GetNode<CanvasLayer>("MainCanvas");
        
        
        _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);

        _lessonHandler = new LessonHandler();
        _lessonHandler.Initialize();
        Adept.Initialize(this, _lessonHandler);
        
        _cogwheelConsole.LogInfo("COGWHEEL " + " initialized.");
        _cogwheelConsole.LogInfo("ADEPT " + Adept.Constants.Version + " initialized.");
        _cogwheelConsole.LogInfo("Type 'list' for a list of commands.");
    }
}