using Godot;
using System;
using System.Threading.Tasks;
using Cirno.Scripts.Components;
using Cirno.Scripts.Enums;

public partial class Chair : StaticBody2D, IIRotateable
{
    [Export]
    public Direction Direction { get; set; } = Direction.Down;

    private AnimatedSprite2D _animatedSprite;
    
    [Export]
    public StringName SpinAnimationName = "Spin";

    [Export] public float SpinTime { get; private set; } = 4f;

    private double _timer = 0f;

    public override void _Ready()
    {
        _animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
        
        //_animatedSprite.Play(Direction.ToString());
    }

    public override void _Process(double delta)
    {
        if (_animatedSprite.Animation != SpinAnimationName) return;
        _timer += delta;

        if (_timer >= SpinTime)
        {
            _timer = 0;
            _animatedSprite.SpeedScale = 0;
        }

    }

    private void OnBulletCollision(Area2D area)
    {
        _animatedSprite.SpeedScale = 1;
        _animatedSprite.Play("Spin");

        _timer = 0;
    }
    
}

