using Godot;

namespace Cirno.Scripts.Interactables;

public partial class AlarmBox : Interactable
{

    private AlarmManager _alarmManager;
    private AnimatedSprite2D _sprite;
    
    public override void _Ready()
    {
        base._Ready();
        _alarmManager = GetNode<AlarmManager>("/root/GameScene/AlarmManager");
        
        _sprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
        
        _alarmManager.AlarmEnabled += AlarmManagerOnAlarmEnabled;
        
        _alarmManager.AlarmDisabled += AlarmManagerOnAlarmDisabled;
        
    }

    private void AlarmManagerOnAlarmDisabled()
    {
        GD.Print("Playing disabled alarm");
        _sprite.Play("default");
    }

    private void AlarmManagerOnAlarmEnabled(Vector2 location)
    {
        GD.Print("Playing enabled alarm");
        _sprite.Play("alarmed");
    }

    public override bool Activate(ActivationType activationType = ActivationType.Toggle)
    {
        if (MeetsRequirements() && _alarmManager.IsAlarmOn)
        {
            _alarmManager.DisableAlarm();
            // disable alarm
            GD.Print("Alarm disabled");
            
            return true;
        }

        return false;
    }
}