using DbCommon.BusinessCore.BaseCore;
using Newtonsoft.Json;
using Pms.DataLibrary.Order;
using ProjectManagementSystem.Common.Core;
using ProjectManagementSystem.Common.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManagementSystem.TaskEvent
{
    public class ProcessApiCallFailed : ICustomProcess
    {
        private ApiCallFailedManager apiCallFailedManager = new ApiCallFailedManager();
        public void CustomProcess(List<TaskData> taskDataList)
        {
            ReCallApi();
        }

        private string ReCallApi()
        {
            string content = null;
            while (true)
            {
                var data = apiCallFailedManager.GetFirstOne();
                if(data == null)
                {
                    break;
                }

                bool result = CustomerApi.LesApi(data.ApiName, data.Body, out content);
                if (result)
                {
                    apiCallFailedManager.Delete(data);
                }
                else
                {
                    break;
                }
            }

            return content;
        }
    }
}
