using System;
using Cirno.Scripts.Enums;
using Godot;

namespace Cirno.Scripts.Interactables.Modules;

public partial class SwitchSpriteChanger : AnimatedSprite2D
{
    [Export]
    public StateSwitch Switch { get; private set; }

    [Export] public StringName OnAnimationName { get; private set; } = "On";
    [Export] public StringName OffAnimationName { get; private set; } = "Off";
    [Export] public StringName DestroyedAnimationName { get; private set; } = "Destroyed";
    [Export] public StringName DisabledAnimationName { get; private set; } = "Disabled";

    public override void _Ready()
    {
        Switch.OnActivated += SwitchOnActivated;
        UpdateSprite();
    }

    private void SwitchOnActivated(ActivationType activationType)
    {
        UpdateSprite();
    }

    private void UpdateSprite()
    {
        switch (Switch.CurrentState)
        {
            case SwitchState.On:
                this.Play(OnAnimationName);
                break;
            case SwitchState.Off:
                this.Play(OffAnimationName);
                break;
            case SwitchState.Destroyed:
                this.Play(DestroyedAnimationName);
                break;
            case SwitchState.Disabled:
                this.Play(DisabledAnimationName);
                break;
        }
    }
}