using VOID.Generic.Objects.Unit.Actions.Exceptions;

namespace VOID.Generic.Objects.Unit.Actions
{
    public class EndTurnAction : AbstractAction
    {
        private readonly UnitObject _unit;

        public EndTurnAction(UnitObject unit)
        {
            _unit = unit;
        }

        public override bool IsInRange() => true;
        public override bool CanSkipQueue() => true;

        protected override void OnEndIt() { }

        protected override void OnCancelIt() { }
        
        public override void CanDoIt()
        {
            Check(
                state == ActionState.Ready,
                UnitActionErrorType.ActionStateIsNotReady);
            Check(
                _unit.basicState.turnManager,
                UnitActionErrorType.UnitNotInTurnManager);
            Check(
                _unit.unitState.isSelfTurn,
                UnitActionErrorType.UnitSelfTurnNotActive);
        }

        protected override void OnDoIt()
        {
            _unit.unitActionQueue.StopQueue();
            _unit.basicState.turnManager.NextTurn();
        }
    }
}