using Intrepid.Core.Messages.Events;
using Intrepid.GameManagers;
using Intrepid.Integration.Input;
using Intrepid.SimpleEvents;
using Intrepid.Utilities;
using Sirenix.OdinInspector;
using UnityEngine;

namespace Intrepid.Core
{
    public class InputManager : EventListener
    {
        [GroupDebug, SerializeField] private InputSchema startInputSchema = InputSchema.Sentinel; // it should be deleted
        [GroupDebug, ShowInInspector, ReadOnly] private InputSchema InputSchema => InputService.Instance?.CurrentInputSchema ?? InputSchema.None;
        
        protected override void InitializeVariables()
        {
        }

        protected override void OnBootstrap()
        {
            InputService.Instance.ChangeInputSchema(startInputSchema); // it should be deleted
        }

        protected override void Subscriptions()
        {
            Subscribe<ChangeInputSchemeEvent>(OnInputSchemeChanged);
        }

        private void OnInputSchemeChanged(ChangeInputSchemeEvent evt)
        {
            InputService.Instance.ChangeInputSchema(evt.InputSchema);
        }

        [GroupDebug, Button(ButtonSizes.Large, ButtonStyle.FoldoutButton)]
        private void Lock()
        {
            InputService.Instance.Locking.Lock();
        }
        
        [GroupDebug, Button(ButtonSizes.Large, ButtonStyle.FoldoutButton)]
        private void Unlock()
        {
            InputService.Instance.Locking.UnLock();
        }
        
        [GroupDebug, Button(ButtonSizes.Large, ButtonStyle.FoldoutButton)]
        private void ChangeInputSchema(InputSchema schema)
        {
            Proxy.Instance.EventBus.Raise(new ChangeInputSchemeEvent
            {
                InputSchema = schema
            });
        }
        
        [GroupDebug, Button(ButtonSizes.Large, ButtonStyle.FoldoutButton)]
        private void OnlyGamepad(bool onlyGamepad)
        {
            InputService.Instance.OnlyGamepad(onlyGamepad);
        }
    }
}