using TagashiFileHub.Communication.IPC;

namespace TagashiFIleHub.Service;

internal class Worker : BackgroundService
{
    private readonly ILogger<Worker>? _logger;
    private readonly TagashiServer _server;

    public Worker(ILogger<Worker>? logger, TagashiServer server)
    {
        _logger = logger;
        _server = server;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        _logger?.LogInformation("Starting service worker");

        await _server.StartAsync("Service", stoppingToken);

        while (!stoppingToken.IsCancellationRequested)
        {
            _logger?.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
            await Task.Delay(1000, stoppingToken);
        }
    }
}