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

namespace Actions {
    public class SpinAction : BaseAction {
        private float totalSpinAmount;

        protected override void Awake() {
            base.Awake();
            ActionPointsCost = 2;
            ActionName = "Spin";
        }

        private void Update() {
            if (!IsActive) return;

            float spinAddAmount = 360f * Time.deltaTime;
            transform.eulerAngles += new Vector3(0, spinAddAmount, 0);
            totalSpinAmount += spinAddAmount;

            if (!(totalSpinAmount >= 360f)) return;
            ActionComplete();
        }

        public override void TakeAction(GridPosition gridPosition, Action onSpinComplete) {
            totalSpinAmount = 0f;
            ActionStart(onSpinComplete);
        }

        public override List<GridPosition> GetValidActionGridPositionList() => new() { Unit.GridPosition };

        protected override EnemyAIAction GetEnemyAIAction(GridPosition gridPosition) => new(gridPosition, 0);
    }
}