package seedu.taskboss.model.task;

import seedu.taskboss.commons.exceptions.IllegalValueException;

//@@author A0144904H
/**
 * Represents a Task's priority level in TaskBoss.
 * Guarantees: immutable; is valid as declared in {@link #isValidPriorityLevel(String)}
 */
public class PriorityLevel {

    private static final String STRING_YES = "Yes";
    private static final String STRING_NO = "No";

    private static final String EMPTY_STRING = "";

    public static final String MESSAGE_PRIORITY_CONSTRAINTS = "Task priority level should only contain"
            + " the words Yes and No (case-insensitive) or the letters y(Y) and n(N)";

    public static final String PRIORITY_HIGH_VALUE = "High priority";
    public static final String PRIORITY_NO_VALUE = "No priority";
    public static final String PRIORITY_REGEX = "^(?:Yes|No|yes|YES|NO|no|y|n|Y|N|yEs"
            + "|yeS|nO|YEs|yES|YeS)$";

    public final String value;
    public final String input;

    /**
     * Validates given priority level.
     *
     * @throws IllegalValueException if given priority level string is invalid.
     */
    public PriorityLevel(String priorityLevel) throws IllegalValueException {
        assert priorityLevel != null;

        String trimmedPriorityLevel = priorityLevel.trim();

        if (EMPTY_STRING.equals(priorityLevel)) {
            this.value = PRIORITY_NO_VALUE;
            this.input = STRING_NO;
        } else {
            if (!isValidPriorityLevel(trimmedPriorityLevel)) {
                throw new IllegalValueException(MESSAGE_PRIORITY_CONSTRAINTS);
            }
            if (trimmedPriorityLevel.contains("y") || trimmedPriorityLevel.contains("Y")) {
                this.value = PRIORITY_HIGH_VALUE;
                this.input = STRING_YES;
            } else {
                this.value = PRIORITY_NO_VALUE;
                this.input = STRING_NO;
            }
        }
    }

    /**
     * Returns true if a given string is a valid task priority level.
     */
    public static boolean isValidPriorityLevel(String test) {
        return test.matches(PRIORITY_REGEX) ||
                EMPTY_STRING.equals(test);
    }

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

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

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

}

@@ -909,30 +909,24 @@
 %0A    public 
-final 
 String value
@@ -938,22 +938,16 @@
  public 
-final 
 String i
@@ -1216,123 +1216,8 @@
 l;%0A%0A
-        String trimmedPriorityLevel = priorityLevel.trim();%0A%0A        if (EMPTY_STRING.equals(priorityLevel)) %7B%0A    
     
@@ -1243,37 +1243,34 @@
 IORITY_NO_VALUE;
+;
 %0A
-    
         this.inp
@@ -1289,37 +1289,77 @@
 NO;%0A        
-%7D else %7B%0A    
+String trimmedPriorityLevel = priorityLevel.trim();%0A%0A
         if (
@@ -1417,20 +1417,16 @@
         
-   
- 
 throw ne
@@ -1484,34 +1484,27 @@
 S);%0A        
-    %7D%0A    
+%7D%0A%0A
         if (
@@ -1583,36 +1583,32 @@
 ) %7B%0A            
-   
- 
 this.value = PRI
@@ -1629,36 +1629,32 @@
 UE;%0A            
-    
 this.input = STR
@@ -1674,152 +1674,17 @@
     
-    %7D else %7B%0A                this.value = PRIORITY_NO_VALUE;%0A                this.input = STRING_NO;%0A            %7D%0A        %7D%0A    %7D%0A%0A    /**%0A    
+%7D%0A%7D%0A%0A/**%0A
  * R
@@ -1746,27 +1746,19 @@
 level.%0A 
-    */%0A    
+*/%0A
 public s
@@ -1803,28 +1803,24 @@
 ing test) %7B%0A
-    
     return t
@@ -1862,20 +1862,16 @@
         
- 
-   
 EMPTY_ST
@@ -1889,27 +1889,19 @@
 (test);%0A
-    %7D%0A%0A    
+%7D%0A%0A
 @Overrid
@@ -1898,28 +1898,24 @@
 %0A%0A@Override%0A
-    
 public Strin
@@ -1925,28 +1925,24 @@
 oString() %7B%0A
-    
     return v
@@ -1947,27 +1947,19 @@
  value;%0A
-    %7D%0A%0A    
+%7D%0A%0A
 @Overrid
@@ -1956,28 +1956,24 @@
 %0A%0A@Override%0A
-    
 public boole
@@ -1998,28 +1998,24 @@
 ther) %7B%0A    
- 
-   
 return other
@@ -2067,20 +2067,16 @@
         
-   
- 
 %7C%7C (othe
@@ -2130,16 +2130,20 @@
 s nulls%0A
+    
         
@@ -2219,27 +2219,19 @@
 e check%0A
-    %7D%0A%0A    
+%7D%0A%0A
 @Overrid
@@ -2232,20 +2232,16 @@
 verride%0A
-    
 public i
@@ -2260,20 +2260,16 @@
 ) %7B%0A    
-  
-  
 return v
@@ -2285,17 +2285,13 @@
 Code();%0A
-    
 %7D%0A%0A%7D%0A

improve code quality of priority constructor