using UnityEngine;
using System;
using System.Collections.Generic;

namespace mgaia.Utils
{
    /// <summary>
    /// Classe para facilitar o trabalho com operações comuns de input
    /// </summary>
    /// <owner>Victor</owner>
    public static class InputExtensions
    {
        /// <summary>
        /// Retorna todos as posições tocadas/clicadas no último update
        /// </summary>
        public static Vector2[] GetTouchedLocations()
        {
            List<Vector2> touchedLocations = new List<Vector2>();

            if (Input.GetMouseButtonDown(Constants.LEFT_MOUSE_BUTTON_INDEX))
            {
                Touch[] touches = Input.touches;

                if (touches.Length > 0)
                {
                    touches.ForEach(touch => touchedLocations.Add(touch.position));
                }
                else
                {
                    touchedLocations.Add(Input.mousePosition);
                }
            }

            return touchedLocations.ToArray();
        }

        /// <summary>
        /// Retorna a primeira posição tocada/clicada no último update
        /// </summary>
        public static Vector2? GetFirstTouchedLocation()
        {
            Vector2[] touchedLocations = GetTouchedLocations();

            return touchedLocations.Length > 0 ? (Vector2?)touchedLocations[0] : null;
        }
    }
}