using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using wispro.sp.share;

namespace wispro.sp.api.Services
{
    public interface IFileTaskService
    {
        public share.FileProcessTask Get(string Id);

        public bool Add(share.FileProcessTask processTask);

        public bool Remove(string Id);
    }

    public class FileTaskCacheService : IFileTaskService
    {
        List<share.FileProcessTask> lstFileTask = new List<FileProcessTask>();

        public bool Add(FileProcessTask processTask)
        {
            if(processTask != null)
            {
                var temObj = lstFileTask.FirstOrDefault(s=>s.Id == processTask.Id);

                if(temObj == null)
                {
                    lstFileTask.Add(processTask);

                    return true;
                }
            }

            return false;
        }

        public FileProcessTask Get(string Id)
        {
            var temObj = lstFileTask.FirstOrDefault(s => s.Id == Id);

            return temObj;
        }

        public bool Remove(string Id)
        {
            var temObj = lstFileTask.FirstOrDefault(s => s.Id == Id);

            if (temObj == null)
            {
                lstFileTask.Remove(temObj);

                return true;
            }
            else
            {
                return false;
            }

           
        }
    }
}
