using PARR.Core.Services.Workload.Interfaces;
using PARR.WorkloadBuilderWorker.Settings;

namespace PARR.WorkloadBuilderWorker
{
    public class Worker : BackgroundService
    {
        private readonly IWorkloadCacheBuilderService workloadCacheBuilderService;
        private readonly WorkerSettings workerSettings;

        public Worker(ILogger<Worker> logger, IWorkloadCacheBuilderService workloadCacheBuilderService, WorkerSettings WorkerSettings)
        {
            this.workloadCacheBuilderService = workloadCacheBuilderService;
            this.workerSettings = WorkerSettings;
        }


        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await workloadCacheBuilderService.ProcessMessagesAsync(workerSettings.MqSettings);
        }

        public override async Task StopAsync(CancellationToken cancellationToken)
        {
            await workloadCacheBuilderService.StopProcessingAsync();
            await base.StopAsync(cancellationToken);
        }
    }
}
