using MainShell.Common;
using MainShell.ProcessResult;
using MW.WorkFlow;
using System;
using System.Threading.Tasks;

namespace MainShell.Process
{
    public class DieRecheckActivity : ActivityAbstractBase
    {
        private readonly DieRecheckService _dieRecheckService;

        public DieRecheckActivity(string name, DieRecheckService dieRecheckService)
            : base(name)
        {
            _dieRecheckService = dieRecheckService ?? throw new ArgumentNullException(nameof(dieRecheckService));
        }

        protected override async Task<ActivityResult> OnExecuteAsync(WorkflowContext context, ActivityControl activityControl)
        {
            await _dieRecheckService.ExecuteAsync(context, activityControl).ConfigureAwait(false);

            DieRecheckProcessResult result = context.GetData<DieRecheckProcessResult>(WorkflowContextKeys.DieRecheckResult);
            if (result == null || !result.IsSuccess)
            {
                return ActivityResult.Failure;
            }

            return ActivityResult.Success;
        }
    }
}
