package seedu.address.model.task;


import seedu.address.commons.exceptions.IllegalValueException;

/**
 * Represents a Task's priority in task manager.
 * Guarantees: immutable; is valid as declared in {@link #isValidPriority(String)}
 */
public class Priority {

    public static final String PRIORITY_1 = "1";
    public static final String PRIORITY_2 = "2";
    public static final String PRIORITY_3 = "3";
    public static final String PRIORITY_TRIVIAL = "trivial";
    public static final String PRIORITY_NORMAL = "normal";
    public static final String PRIORITY_IMPORTANT = "important";
    public static final String PRIORITY_EMPTY = "";

    public static final String DEFAULT_PRIORITY = PRIORITY_2;

    public static final String MESSAGE_PRIORITY_CONSTRAINTS = "task priority can only be 1, 2, 3, trivial, normal, or important";
    //TODO: public static final String DATE_VALIDATION_REGEX =

    public final String value;

    /**
     * Validity given priority.
     *
     * @throws IllegalValueException if given priority string is invalid.
     */
    public Priority(String priority) throws IllegalValueException {
        if (priority == null) {
            this.value = DEFAULT_PRIORITY;
        } else {
            String trimmedPriority = priority.trim();
            if (!isValidPriority(trimmedPriority)) {
                throw new IllegalValueException(MESSAGE_PRIORITY_CONSTRAINTS + " " + trimmedPriority);
            }
            this.value = convert(trimmedPriority);
        }
    }

    /**
     * Returns if a given string is a valid priority.
     */
    public static boolean isValidPriority(String test) {
        return test.equalsIgnoreCase(PRIORITY_1) || test.equalsIgnoreCase(PRIORITY_2) ||
                test.equalsIgnoreCase(PRIORITY_3) || test.equalsIgnoreCase(PRIORITY_TRIVIAL) ||
                test.equalsIgnoreCase(PRIORITY_NORMAL) || test.equalsIgnoreCase(PRIORITY_IMPORTANT) ||
                test.equals(PRIORITY_EMPTY);
    }

    /**
     * Convert English expressions into digits expressions
     */
    public String convert(String value) {
        if (value.equals(PRIORITY_TRIVIAL)) {
            return PRIORITY_1;
        } else if (value.equals(PRIORITY_NORMAL) || value.equals(PRIORITY_EMPTY)) {
            return PRIORITY_2;
        } else if (value.equals(PRIORITY_IMPORTANT)) {
            return PRIORITY_3;
        } else {
            return value;
        }
    }

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

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

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

@@ -844,15 +844,12 @@
     
-//TODO:
+%0A   
  pub
@@ -876,12 +876,16 @@
 ing 
-DATE
+PRIORITY
 _VAL
@@ -899,28 +899,79 @@
 _REGEX =
+ PRIORITY_1 + %22%7C%22 + PRIORITY_2 + %22%7C%22 + PRIORITY_3;
 %0A%0A    p
-ublic
+rivate
  final S
@@ -1323,24 +1323,89 @@
 ity.trim();%0A
+            String convertedPriority = convert(trimmedPriority);%0A
             
@@ -1425,21 +1425,23 @@
 riority(
-trimm
+convert
 edPriori
@@ -1527,32 +1527,8 @@
 INTS
- + %22 %22 + trimmedPriority
 );%0A 
@@ -1564,38 +1564,32 @@
 .value = convert
-(trimm
 edPriority);%0A   
@@ -1574,33 +1574,32 @@
 onvertedPriority
-)
 ;%0A        %7D%0A    
@@ -1752,318 +1752,41 @@
 est.
-equalsIgnoreCase(PRIORITY_1) %7C%7C test.equalsIgnoreCase(PRIORITY_2) %7C%7C%0A                test.equalsIgnoreCase(PRIORITY_3) %7C%7C test.equalsIgnoreCase(PRIORITY_TRIVIAL) %7C%7C%0A                test.equalsIgnoreCase(PRIORITY_NORMAL) %7C%7C test.equalsIgnoreCase(PRIORITY_IMPORTANT) %7C%7C%0A                test.equals(PRIORITY_EMPTY
+matches(PRIORITY_VALIDATION_REGEX
 );%0A 
@@ -1873,24 +1873,31 @@
 %0A    public 
+static 
 String conve
@@ -1923,20 +1923,24 @@
         
-if (
+value = 
 value.eq
@@ -1948,47 +1948,92 @@
 als(
-PRIORITY_TRIVIAL)) %7B%0A            return
+%22%22)? DEFAULT_PRIORITY: value;%0A        value = value.replaceFirst(PRIORITY_IMPORTANT,
  PRI
@@ -2038,17 +2038,18 @@
 RIORITY_
-1
+3)
 ;%0A      
@@ -2054,102 +2054,60 @@
     
-%7D else if (value.equals(PRIORITY_NORMAL) %7C%7C value.equals(PRIORITY_EMPTY)) %7B%0A            return
+value = value.replaceFirst(%22(?i)%22 + PRIORITY_NORMAL,
  PRI
@@ -2113,16 +2113,17 @@
 IORITY_2
+)
 ;%0A      
@@ -2128,59 +2128,75 @@
     
-%7D else if (value.equals(PRIORITY_IMPORTANT)) %7B%0A    
+value = value.replaceFirst(%22(?i)%22 + PRIORITY_TRIVIAL, PRIORITY_1);%0A
     
@@ -2210,41 +2210,53 @@
 urn 
-PRIORITY_3
+value
 ;%0A    
+%7D%0A%0A
     
-%7D else %7B%0A    
+public String getValue() %7B%0A
     
@@ -2270,31 +2270,30 @@
 urn 
+this.
 value;%0A
-        %7D%0A
     %7D%0A
+    
 %0A   

Add regex for priority