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 CheckEndTimeStrategy : IExamStrategy
    {
        public string ErroMessage { get; private set; }

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

        private IExamStrategy _next;

        private DateTime _examEndTime;

        private DateTime? _startTime;

        private IExamStrategy _current;


        public CheckEndTimeStrategy(DateTime examEndTime, DateTime? startTime)
        {
            _examEndTime = examEndTime;
            _startTime = startTime;
        }


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

        public bool Validate()
        {
            if (_examEndTime < _startTime)
            {
                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;
        }
    }
}
