using PARR.EsppScheduleSync;

namespace PARR.EsppScheduleSyncWorker
{
    public class Worker : BackgroundService
    {
        private readonly ILogger<Worker> _logger;
        private readonly IScheduleSyncher scheduleSyncher;

        public Worker(ILogger<Worker> logger, IScheduleSyncher scheduleSyncher)
        {
            _logger = logger;
            this.scheduleSyncher = scheduleSyncher;
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
           await scheduleSyncher.StartAsync();
        }

        public override Task StopAsync(CancellationToken cancellationToken)
        {
            scheduleSyncher.StopAsync().Wait();

            return base.StopAsync(cancellationToken);
        }
    }
}