package seedu.doist.model.task;

import seedu.doist.commons.exceptions.IllegalValueException;

/**
 * Represents a task's priority in the to-do list
 * Guarantees: immutable; is valid as declared in {@link #isValidPriority(String)}
 * Default value is 1 if not set by user.
 */
public class Priority {

    public static final String EXAMPLE = "HIGH";
    public static final String MESSAGE_PRIORITY_CONSTRAINTS = "Task priority should be 'NORMAL', "
            + "'IMPORTANT' or 'VERY IMPORTANT'";
    public static final PriorityLevel DEFAULT_PRIORITY = PriorityLevel.NORMAL;

    public enum PriorityLevel {
        NORMAL("Normal"), IMPORTANT("Important"), VERY_IMPORTANT("Very Important");

        private String strValue;
        PriorityLevel(String value) {
            this.strValue = value;
        }

        @Override
        public String toString() {
            return this.strValue;
        }
    }
    public final PriorityLevel priority;

    /**
     * If no parameters are given, it is set to default priority
     */
    public Priority() {
        this.priority = DEFAULT_PRIORITY;
    }

    /**
     * Validates given string priority.
     *
     * @throws IllegalValueException if given priority string is invalid.
     */
    public Priority(String priority) throws IllegalValueException {
        final String processedPriority = processPriorityString(priority);
        if (!isValidPriority(processedPriority)) {
            throw new IllegalValueException(MESSAGE_PRIORITY_CONSTRAINTS);
        }
        this.priority = PriorityLevel.valueOf(processedPriority);
    }

    public PriorityLevel getPriorityLevel() {
        return priority;
    }

    /**
     * Returns true if a given string is a valid priority
     */
    public static boolean isValidPriority(String priority) {
        return priority.equals(PriorityLevel.VERY_IMPORTANT.toString())
                || priority.equals(PriorityLevel.IMPORTANT.toString())
                || priority.equals(PriorityLevel.NORMAL.toString());
    }

    /**
     * Process string to remove trailing whitespace, spaces and
     * change all characters to upper case so that it will be a
     * valid priority string
     * @returns string of the processed priority string
     */
    public static String processPriorityString(String priority) {
        String processedPriority = priority.trim();
        processedPriority = processedPriority.replaceAll(" ", "");
        processedPriority = processedPriority.toUpperCase();
        return processedPriority;
    }

    @Override
    public String toString() {
        return priority.toString();
    }

    @Override
    public boolean equals(Object other) {
        return other == this // short circuit if same object
                || (other instanceof Priority // instanceof handles nulls
                && this.priority.equals((((Priority) other).priority))); // state check
    }

    @Override
    public int hashCode() {
        return priority.toString().hashCode();
    }

}

@@ -249,9 +249,14 @@
  is 
-1
+NORMAL
  if 
@@ -1868,32 +1868,28 @@
 Y_IMPORTANT.
-toString
+name
 ())%0A        
@@ -1939,24 +1939,20 @@
 PORTANT.
-toString
+name
 ())%0A    
@@ -2003,24 +2003,20 @@
 .NORMAL.
-toString
+name
 ());%0A   
@@ -2429,16 +2429,17 @@
 l(%22 %22, %22
+_
 %22);%0A    

Fix bug with priority isValid