package seedu.flexitrack.model.task;

import seedu.flexitrack.commons.exceptions.IllegalValueException;

/**
 * Represents a Person's name in the address book. Guarantees: immutable; is
 * valid as declared in {@link #isValidName(String)}
 */
public class Name {

    public static final String MESSAGE_NAME_CONSTRAINTS = "Task should be spaces or alphanumeric characters";
    public static final String NAME_VALIDATION_REGEX = ".+";
    public static final String DONE_PREFIX = "(Done) ";
    public static final String BLOCK_PREFIX = "(Blocked) ";
        
    private String isDonePrefix;
    private String fullName;
    private String isBlockPrefix;
    
    
    /**
     * Validates given name.
     *
     * @throws IllegalValueException
     *             if given name string is invalid.
     */
    public Name(String name) throws IllegalValueException {
        assert name != null;
        name = name.trim();
        if (!isValidName(name)) {
            throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS);
        }
        if (name.contains(DONE_PREFIX)){
            this.isDonePrefix = name.substring(0, 7); 
            this.fullName = name.substring(7);
        } else {
            this.fullName = name;
            this.isDonePrefix = ""; 
        }
        if (name.contains(BLOCK_PREFIX)){
            this.isBlockPrefix = name.substring(0, 10); 
            this.fullName = name.substring(10);
        } else {
            this.fullName = name;
            this.isBlockPrefix = ""; 
        }
    }

    /**
     * Returns true if a given string is a valid person name.
     */
    public static boolean isValidName(String test) {
        return test.matches(NAME_VALIDATION_REGEX);
    }

    public void setName(String name) {
        this.fullName = name;
    }

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

    @Override
    public int hashCode() {
        return fullName.hashCode();
    }
    
    public boolean getIsDone(){ 
        return isDonePrefix.equals(DONE_PREFIX);
    }
    
    public boolean getIsBlock() {
        return isBlockPrefix.equals(BLOCK_PREFIX);
    }
    
    public String setBlock(){ 
        return isBlockPrefix = BLOCK_PREFIX; 
    }
    
  //@@author A0127686R
    @Override
    public String toString(){ 
        return isDonePrefix + isBlockPrefix + fullName; 
    }

    public String getNameOnly(){ 
        return fullName; 
    }

    public String setAsMark(){ 
        return isDonePrefix = DONE_PREFIX; 
    }

    public String setAsUnmark(){ 
        return isDonePrefix = ""; 
    }
}

@@ -605,24 +605,29 @@
  String 
-fullName
+isBlockPrefix
 ;%0A    pr
@@ -639,35 +639,21 @@
  String 
-isBlockPrefix;%0A    
+name;
 %0A    %0A  
@@ -734,27 +734,8 @@
 tion
-%0A     *            
  if 
@@ -1068,32 +1068,70 @@
 s.isDonePrefix =
+ DONE_PREFIX; %0A            this.name =
  name.substring(
@@ -1134,15 +1134,11 @@
 ing(
-0, 
 7);
- 
 %0A   
@@ -1142,34 +1142,25 @@
             
-this.fullN
+n
 ame = name.s
@@ -1198,37 +1198,33 @@
            this.
-fullN
+n
 ame = name;%0A    
@@ -1345,29 +1345,20 @@
 x = 
-name.substring(0, 10)
+BLOCK_PREFIX
 ; %0A 
@@ -1365,37 +1365,33 @@
            this.
-fullN
+n
 ame = name.subst
@@ -1426,37 +1426,33 @@
            this.
-fullN
+n
 ame = name;%0A    
@@ -1744,21 +1744,17 @@
    this.
-fullN
+n
 ame = na
@@ -1983,21 +1983,17 @@
 && this.
-fullN
+n
 ame.equa
@@ -2010,21 +2010,17 @@
  other).
-fullN
+n
 ame)); /
@@ -2175,21 +2175,17 @@
  return 
-fullN
+n
 ame.hash
@@ -2594,21 +2594,17 @@
 refix + 
-fullN
+n
 ame; %0A  
@@ -2661,13 +2661,9 @@
 urn 
-fullN
+n
 ame;
@@ -2780,32 +2780,78 @@
 setAsUnmark()%7B %0A
+        name = name.replace(DONE_PREFIX, %22%22);%0A
         return i

fix mark