package tars.model.task;

import tars.model.tag.UniqueTagList;

/**
 * A read-only immutable interface for a Task in TARS.
 * Implementations should guarantee: details are present and not null, field values are validated.
 */
public interface ReadOnlyTask {
    
    public static final String PRIORITY_HIGH = "high";
    public static final String PRIORITY_MEDIUM = "medium";
    public static final String PRIORITY_LOW = "low";

    public static final String PRIORITY_H = "h";
    public static final String PRIORITY_M = "m";
    public static final String PRIORITY_L = "l";

    Name getName();
    DateTime getDateTime();
    Priority getPriority();
    Status getStatus();
    

    /**
     * The returned TagList is a deep copy of the internal TagList,
     * changes on the returned list will not affect the task's internal tags.
     */
    UniqueTagList getTags();

    /**
     * Returns true if both have the same state. (interfaces cannot override .equals)
     */
    default boolean isSameStateAs(ReadOnlyTask other) {
        return other == this // short circuit if same object
                || (other != null // this is first to avoid NPE below
                && other.getName().equals(this.getName()) // state checks here onwards
                && other.getDateTime().equals(this.getDateTime())
                && other.getPriority().equals(this.getPriority())
                && other.getTags().equals(this.getTags())
                && other.getStatus().equals(this.getStatus()));
    }

    /**
     * Formats the task as text, showing all contact details.
     */
    default String getAsText() {
        final StringBuilder builder = new StringBuilder();
        builder.append(getName())
                .append(" DateTime: ")
                .append(getDateTime())
                .append(" Priority: ")
                .append(priorityString())
                .append(" Status: ")
                .append(getStatus().toString())
                .append(" Tags: ");
        getTags().forEach(builder::append);
        return builder.toString();
    }
    
    /**
     * Returns a string representation of this Task's priority
     */
    default String priorityString() {
        String level = "";
        switch (getPriority().toString()) {
        case PRIORITY_H:
            level = PRIORITY_HIGH;
            break;
        case PRIORITY_M:
            level = PRIORITY_MEDIUM;
            break;
        case PRIORITY_L:
            level = PRIORITY_LOW;
            break;
        default:
            level = "";
            break;
        }
        return level;
    }

    /**
     * Returns a string representation of this Task's tags
     */
    default String tagsString() {
        final StringBuffer buffer = new StringBuffer();
        final String separator = ", ";
        getTags().forEach(tag -> buffer.append(tag).append(separator));
        if (buffer.length() == 0) {
            return "";
        } else {
            return buffer.substring(0, buffer.length() - separator.length());
        }
    }

}

@@ -251,20 +251,16 @@
 yTask %7B%0A
-    
 %0A    pub
@@ -668,20 +668,16 @@
 atus();%0A
-    
 %0A%0A    /*
@@ -1699,32 +1699,24 @@
 (getName())%0A
-        
         .app
@@ -1738,32 +1738,24 @@
  %22)%0A        
-      
-  
 .append(getD
@@ -1769,32 +1769,24 @@
 ())%0A        
-     
-   
 .append(%22 Pr
@@ -1800,32 +1800,24 @@
  %22)%0A        
-    
-    
 .append(prio
@@ -1834,32 +1834,24 @@
 ())%0A        
-   
-     
 .append(%22 St
@@ -1863,32 +1863,24 @@
  %22)%0A        
-  
-      
 .append(getS
@@ -1895,32 +1895,24 @@
 toString())%0A
-        
         .app
@@ -2012,20 +2012,16 @@
 ;%0A    %7D%0A
-    
 %0A    /**

Correct indentation