using Hotline.Application.Exam.Interface.Strategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotline.Application.Exam.Strategy
{
    public class CheckValidateCountStrategy : IExamStrategy
    {
        public string ErroMessage { get; private set; }

        public Func<object> CallBack { get; set; }

        private IExamStrategy _next;

        private int _validateCount;

        private int _count;

        private IExamStrategy _current;

        public CheckValidateCountStrategy(int validateCount, int count)
        {
            _validateCount = validateCount;
            _count = count;
        }


        public void SetNext(IExamStrategy examStrategy)
        {
            _next = examStrategy;
        }

        public bool Validate()
        {
            if (_count>_validateCount)
            {
                ErroMessage = "已超过可考次数，考试结束";
                _current = this;
                return false;
            }
            _current = _next;

            if (_next == null) return true;

            return _next.Validate();
        }
        public object GetResult()
        {
            if (_current!=null && _current.CallBack != null)
                return _current.CallBack();

            return null;
        }
    }
}
