using Microsoft.Extensions.DependencyInjection;
using PARR.EsppTemplateSync;
using System;

namespace PARR.EsppTemplateSyncWorker
{
    public class Worker : BackgroundService
    {
        private readonly ILogger<Worker> _logger;
        private readonly ITemplateSyncer templateSyncer;

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

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

        public override Task StopAsync(CancellationToken cancellationToken)
        {
            templateSyncer.StopAsync().Wait();
            return base.StopAsync(cancellationToken);
        }
    }
}