﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyQueues
{
    public class SimplePriorityQueue<T> : ISimplePriorityQueue<T>
    {
        private Queue<T> normalQueue;
        private Queue<T> priorQueue;

        public SimplePriorityQueue()
        {
            normalQueue = new Queue<T>();
            priorQueue = new Queue<T>();
        }
        
        public void Put(T item, bool hiprio = false)
        {
            if (hiprio)
            {
                priorQueue.Enqueue(item);
            }
            else
            {
                normalQueue.Enqueue(item);
            }
        }

        public T Get()
        {
            if (priorQueue.Count > 0)
            {
                priorQueue.Dequeue();
            }
            else if (normalQueue.Count > 0)
            {
                normalQueue.Dequeue();
            }            
            throw new InvalidOperationException("Queue is empty.");
        }

        public bool IsEmpty()
        {
            return priorQueue.Count == 0 && normalQueue.Count == 0;     
        }

        /*
        //Kod, ktery k prochodu daty pouziva v samostatne tride implementovany iterator.
        public IEnumerator<T> GetEnumerator()
        {
            Queue<T> test = new Queue<T>();

            foreach (T q in priorQueue)
            {
                test.Enqueue(q);
            }
            foreach (T q in normalQueue)
            {
                test.Enqueue(q);
            }
            return new PriorityQueueEnumerator<T>(test);
        }*/

        public IEnumerator<T> GetEnumerator()
        {
            foreach (T q in priorQueue)
            {
                yield return q;
            }
            foreach (T q in normalQueue)
            {
                yield return q;
            }
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
