package org.academiadecodigo.bootcamp11.priorityqueue;

import java.util.PriorityQueue;
import java.util.Queue;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class TodoList {

    public enum Importance {
        HIGH,
        MEDIUM,
        LOW
    }

    private Queue<TodoItem> list = new PriorityQueue<>();

    public void add(Importance importance, int priority, String message) {
        TodoItem newItem = new TodoItem(importance, priority, message);
        list.add(newItem);
    }

    public TodoItem remove() {
        TodoItem toRemove = list.remove();
        return toRemove;
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }

    private class TodoItem implements Comparable<TodoItem> {
        private Importance importance;
        private int priority;
        private String message;

        public TodoItem(Importance importance, int priority, String message) {
            this.importance = importance;
            this.priority = priority;
            this.message = message;
        }

        public Importance getImportance() {
            return this.importance;
        }

        public int getPriority() {
            return priority;
        }

        @Override
        public String toString() {
            return message;
        }

        @Override
        public int compareTo(TodoItem o) {
            int cmp = this.importance.compareTo(o.getImportance());
            if (cmp == 0) {
                cmp = Integer.compare(this.priority, o.getPriority());
            }
            return cmp;
        }
    }
}
