using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Modules.State;
using Station46.Modules.Holes.Scripts;
using Station46.Scripts;
using UnityEngine;

namespace Station46.Modules.Hoop.Scripts
{
    [RequireComponent(typeof(Animator), typeof(Hole))]
    public class ButtonHoop : ModuleState
    {
        private static readonly int PressedHash = Animator.StringToHash("Pressed");

        public Hole Button { get; private set; }

        private Animator _animator;

        private void Awake()
        {
            _animator = GetComponent<Animator>();
            Button = GetComponent<Hole>();
        }

        private void Start()
        {
            Button.ButtonEvent += (_, type) =>
            {
                // ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
                switch (type)
                {
                    case ButtonEventType.Pressed:
                        _animator.SetBool(PressedHash, true);
                        break;
                    case ButtonEventType.Released:
                        _animator.SetBool(PressedHash, false);
                        break;
                }
            };
        }

        public override void SetModule(Module module) {}
    }
}