using ManagementApp.AServices.Microsoft365;
using ManagementApp.AServices.ThreadManage;
using Microsoft.Identity.Web;
using System.Collections.Concurrent;

namespace ManagementApp.AServices
{
    public class Microsoft365Service : BackgroundService, IDisposable
    {
        
        private readonly IConcurrentTasks _task;
        public Microsoft365Service(IConcurrentTasks tasks) {
            _task = tasks;
        }


        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await DoWork(stoppingToken);
        }

        private async Task DoWork(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                var workItem = await _task.First(stoppingToken);
               
                try
                {
                    await workItem(stoppingToken);
                }
                catch (Exception ex)
                {
                    
                }
            }
        }

        public override async Task StopAsync(CancellationToken stoppingToken)
        {
            await base.StopAsync(stoppingToken);
        }

        public override void Dispose()
        {
            throw new NotImplementedException();
        }
    }
}
