using Services.Interfaces;
using UnityEngine;
using VContainer.Unity;
using Views;

namespace Services
{
    public class LevelEntryPoint : IStartable
    {
        private readonly IObjectPool<GemView> gemViewPool;
        private readonly IGameBoardService gameBoardService;
        private readonly IInputService inputService;
        
        public LevelEntryPoint(IObjectPool<GemView> gemViewPool, IGameBoardService gameBoardService, IInputService inputService)
        {
            this.gemViewPool = gemViewPool;
            this.gameBoardService = gameBoardService;
            this.inputService = inputService;
        }

        public void Start()
        {
            this.gameBoardService.Setup();
            this.inputService.OnSwapRequested += HandleSwapRequest;
        }
        
        private void HandleSwapRequest(Vector2Int from, Vector2Int to) {
            this.gameBoardService.TrySwap(from, to);   
        }
    }
}