using System.Text.Json.Serialization;

namespace Managing.Core.FixedSizedQueue;

public class FixedSizeQueue<T> : Queue<T>
{
    private readonly int _maxSize;

    /// <summary>
    /// Parameterless constructor for serialization support
    /// </summary>
    public FixedSizeQueue() : this(500) // Default size
    {
    }

    [JsonConstructor]
    public FixedSizeQueue(int maxSize) => _maxSize = maxSize;

    /// <summary>
    /// Gets the maximum size of the queue (for serialization)
    /// </summary>
    public int MaxSize => _maxSize;

    public new void Enqueue(T item)
    {
        while (Count >= _maxSize) Dequeue();
        base.Enqueue(item);
    }
}