// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package vnet

import (
	
)

type chunkQueue struct {
	chunks       []Chunk
	maxSize      int // 0 or negative value: unlimited
	maxBytes     int // 0 or negative value: unlimited
	currentBytes int
	mutex        sync.RWMutex
}

func newChunkQueue( int,  int) *chunkQueue {
	return &chunkQueue{
		chunks:       []Chunk{},
		maxSize:      ,
		maxBytes:     ,
		currentBytes: 0,
		mutex:        sync.RWMutex{},
	}
}

func ( *chunkQueue) ( Chunk) bool {
	.mutex.Lock()
	defer .mutex.Unlock()

	if .maxSize > 0 && len(.chunks) >= .maxSize {
		return false // dropped
	}
	if .maxBytes > 0 && .currentBytes+len(.UserData()) >= .maxBytes {
		return false
	}

	.currentBytes += len(.UserData())
	.chunks = append(.chunks, )
	return true
}

func ( *chunkQueue) () (Chunk, bool) {
	.mutex.Lock()
	defer .mutex.Unlock()

	if len(.chunks) == 0 {
		return nil, false
	}

	 := .chunks[0]
	.chunks = .chunks[1:]
	.currentBytes -= len(.UserData())

	return , true
}

func ( *chunkQueue) () Chunk {
	.mutex.RLock()
	defer .mutex.RUnlock()

	if len(.chunks) == 0 {
		return nil
	}

	return .chunks[0]
}