package werkbook.task.model.task;

import werkbook.task.model.tag.UniqueTagList;

/**
 * A read-only immutable interface for a Task in the task list.
 * Implementations should guarantee: details are present and not null, field values are validated.
 */
public interface ReadOnlyTask {

    Name getName();
    Description getDescription();
    StartDateTime getStartDateTime();
    EndDateTime getEndDateTime();

    /**
     * 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.getDescription().equals(this.getDescription())
                && other.getStartDateTime().equals(this.getStartDateTime())
                && other.getEndDateTime().equals(this.getEndDateTime()));
    }

    /**
     * Formats the task as text, showing all task details.
     */
    default String getAsText() {
        final StringBuilder builder = new StringBuilder();
        builder.append(getName())
                .append(" Description: ")
                .append(getDescription())
                .append(" Start Date/Time: ")
                .append(getStartDateTime())
                .append(" End Date/Time: ")
                .append(getEndDateTime())
                .append(" Status: ");
        getTags().forEach(builder::append);
        return builder.toString();
    }

}

@@ -1203,16 +1203,41 @@
 %0A    %7D%0A%0A
+    //@@author A0139903B%0A
     /**%0A
@@ -1281,12 +1281,8 @@
 ing 
-all 
 task
@@ -1289,17 +1289,27 @@
  details
-.
+ if present
 %0A     */
@@ -1447,28 +1447,24 @@
         
-    
 .append(
 %22 Descri
@@ -1455,18 +1455,19 @@
 .append(
-%22 
+get
 Descript
@@ -1473,37 +1473,58 @@
 tion
-: %22)%0A                .append(
+().toString().isEmpty() ? %22%22 : %22 Description: %22 + 
 getD
@@ -1545,36 +1545,32 @@
             
-    
 .append(
 %22 Start Date
@@ -1561,54 +1561,59 @@
 end(
-%22 
+!get
 Start
- 
 Date
-/
 Time
-: %22)%0A                .append(
+().isPresent() ? %22%22 : %22 From: %22 + 
 getS
@@ -1640,28 +1640,24 @@
         
-    
 .append(
 %22 End Da
@@ -1652,32 +1652,97 @@
 end(
-%22 End 
+!getEndDateTime().isPresent() ? %22%22 : getStart
 Date
-/
 Time
+().isPresent() ? %22 To: %22 : %22 By
 : %22)%0A
-    
     
@@ -1757,16 +1757,17 @@
 .append(
+!
 getEndDa
@@ -1766,38 +1766,70 @@
 getEndDateTime()
-)%0A    
+.isPresent() ? %22%22 : getEndDateTime())%0A
             .app
@@ -1925,17 +1925,32 @@
 ring();%0A
-
     %7D
+%0A    //@@author
 %0A%0A%7D%0A

Modify string builder to only include details that are present