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

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

        public LeaveTurnAction(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);
            Check(
                _unit.basicState.turnManager.CanObjectExit(_unit),
                UnitActionErrorType.EnemiesAreTooClose);
        }

        protected override void OnDoIt()
        {
            _unit.basicState.turnManager.ObjectExit(_unit);
        }
    }
}