using Godot;

namespace Cirno.Scripts.Resources.Events;

[GlobalClass]
public partial class ControlEnemyEvent : EventResource
{
    [Export]
    public NodePath Target { get; set; }
    
    private Node2D _parent;
    
    private GameManager _gameManager;
    private bool _isComplete = false;
    public override bool IsComplete()
    {
        return _isComplete;
    }
    
    public override void Init(Node2D parent)
    {
        _gameManager = parent.GetGameManager();
        _parent = parent;
    }
    
    public override void Start(Node2D parentNode)
    {
        _isComplete = false;

        if (_parent.GetNode<Node2D>(Target) is Enemy enemy)
        {
            _gameManager.CameraTargetObject(enemy);
            GameManager.Instance.Player.SetState(PlayerState.Controlling);
           // _gameManager.Player.RequestMovementDisable(true);
            enemy.AssumeControl();
            // TODO: Do this on the enemy as a module instead
            // if (_gameManager.Player.WingsSprite != null)
            // {
            //     var sprite = new Sprite2D();
            //     sprite.SetTexture(_gameManager.Player.WingsSprite);
            //     //sprite.GlobalPosition = enemy.GlobalPosition;
            //     sprite.SetZIndex(1);
            //     enemy.CallDeferred("add_child", sprite);
            // }
        }

        _isComplete = true;
    }
    
    public override void UpdateEvent(double delta) { }
    
}