/**
 * 
 */
package tars.model.task;

import java.time.DateTimeException;
import java.util.ArrayList;
import java.util.Arrays;

import tars.commons.exceptions.IllegalValueException;
import tars.model.tag.UniqueTagList;
import tars.model.task.DateTime.IllegalDateException;

/**
 * @@author A0124333U
 *
 */
public class TaskQuery extends Task {

    private String tagQuery = "";
    private String statusString = "";
    private final static String NEWLINE = "\n";

    public TaskQuery() {
    }

    public TaskQuery(Name name, DateTime dateTime, Priority priority, Status status, UniqueTagList tags) {
        super(name, dateTime, priority, status, tags);
    }

    /* --------------- SETTER METHODS -------------------- */

    public void createNameQuery(String nameQueryString) throws IllegalValueException {
        name = new Name(nameQueryString);
    }

    public void createDateTimeQuery(String[] dateTimeQueryString) throws DateTimeException, IllegalDateException {
        dateTime = new DateTime(dateTimeQueryString[0], dateTimeQueryString[1]);
    }

    public void createPriorityQuery(String priorityString) throws IllegalValueException {

        /*
         * To convert long versions of priority strings (i.e. high, medium, low)
         * into characters (i.e. h, m, l)
         */
        switch (priorityString) {
        case PRIORITY_HIGH:
            priorityString = PRIORITY_H;
            break;

        case PRIORITY_MEDIUM:
            priorityString = PRIORITY_M;
            break;

        case PRIORITY_LOW:
            priorityString = PRIORITY_L;
            break;
        }

        priority = new Priority(priorityString);
    }

    public void createStatusQuery(Boolean statusQuery) {
        status = new Status();
        status.status = statusQuery;
    }

    public void createTagsQuery(String tagQueryString) {
        tagQuery = tagQueryString;
    }

    /* --------------- GETTER METHODS -------------------- */

    public ArrayList<String> getNameKeywordsAsList() {
        return new ArrayList<String>(Arrays.asList(getName().taskName.split(" ")));
    }

    public DateTime getDateTimeQueryRange() {
        if (getDateTime().getEndDate() != null) {
            return getDateTime();
        } else {
            return null;
        }
    }

    public ArrayList<String> getPriorityKeywordsAsList() {
        return new ArrayList<String>(Arrays.asList(priorityString()));
    }

    public String getStatusQuery() {
        if (status != null) {
            statusString = status.toString();
        }
        return statusString;
    }

    public ArrayList<String> getTagKeywordsAsList() {
        return new ArrayList<String>(Arrays.asList(tagQuery.split(",")));
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        builder.append("Filter Search Keywords: ").append("[Task Name: ").append(getName()).append("] [DateTime: ")
                .append(getDateTime()).append("] [Priority: ").append(priorityString()).append("] [Status: ")
                .append(statusString).append("] [Tags: ").append(tagQuery).append("]");

        return builder.toString();
    }

}

@@ -2886,232 +2886,582 @@
 : %22)
-.append(%22%5BTask Name: %22).append(getName()).append(%22%5D %5BDateTime: %22)%0A                .append(getDateTime()).append(%22%5D %5BPriority: %22).append(priorityString()).append(%22%5D %5BStatus: %22)%0A                .append(statusString).append(%22%5D 
+;%0A%0A        if (getName().toString() != %22%22) %7B%0A            builder.append(%22%5BTask Name: %22).append(getName()).append(%22%5D %22);%0A        %7D%0A        if (getDateTime().getEndDate() != null) %7B%0A            builder.append(%22%5BDateTime: %22).append(getDateTime()).append(%22%5D %22);%0A        %7D%0A        if (priorityString() != %22%22) %7B%0A            builder.append(%22%5BPriority: %22).append(priorityString()).append(%22%5D %22);%0A        %7D%0A        if (statusString != %22%22) %7B%0A            builder.append(%22%5BStatus: %22).append(statusString).append(%22%5D %22);%0A        %7D%0A        if (tagQuery != %22%22) %7B%0A            builder.append(%22
 %5BTag
@@ -3495,16 +3495,26 @@
 nd(%22%5D%22);
+%0A        %7D
 %0A%0A      

Remove displayed labels that are not used for filter search