import uuid
from queue import Queue
from queue import Empty


class SimpleQueue:

    def __init__(self, ack=False):
        self._queue = Queue()
        self._dict = {}
        self._ack = ack

    def put(self, data):
        _qid = str(uuid.uuid1())
        self._queue.put((data, _qid))
        self._dict[_qid] = data
        return _qid

    def put_batch(self, data_list):
        qid_list = [self.put(_item) for _item in data_list]
        return qid_list

    def get(self, block=False, timeout=None):
        try:
            _data, _qid = self._queue.get(block=block, timeout=timeout)
            if not self._ack:
                del self._dict[_qid]
            return _data, _qid
        except Empty:
            return None, None

    def ack(self, qid):
        if not self._ack:
            return True
        if qid is None:
            return False
        del self._dict[qid]
        return True

    def queue_size(self):
        return self._queue.qsize()

    def dict_size(self):
        return len(self._dict)