using System.Collections.Concurrent;
using BLW_Log.Models;
using Common;
using Commonlib;
using DAL.PGModels;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json;
using static BLW_Log.Controllers.LowerMachineLogController;

namespace BLW_Log.services
{
    public record N
    {
        public string DeviceName { get; set; }
        public string DeviceType { get; set; }
        public string Address { get; set; }
        public ushort Status { get; set; }
    }
    public class TaskQueue
    {
        public readonly ConcurrentQueue<string> _tasks = new ConcurrentQueue<string>();
        private readonly SemaphoreSlim _signal = new(0);

        public void EnqueueTask(string task)
        {
            _tasks.Enqueue(task);
            _signal.Release();
        }

        public async Task<string> DequeueAsync()
        {
            await _signal.WaitAsync();
            _tasks.TryDequeue(out var task);
            return task!;
        }
    }
    public class BackgroundTaskService : BackgroundService
    {
        private readonly TaskQueue _queue;

        public readonly IMemoryCache _memoryCache;
        public BackgroundTaskService(TaskQueue queue, IMemoryCache cache)
        {
            this._queue = queue;
            this._memoryCache = cache;
        }

        async protected override Task ExecuteAsync(CancellationToken ct)
        {
            await Task.CompletedTask;
        }
    }
}
