package guitests.guihandles;
// @@author: A0160076L
import java.util.List;
import java.util.stream.Collectors;

import guitests.GuiRobot;
import javafx.scene.Node;
import javafx.scene.control.Labeled;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
import seedu.doit.model.item.ReadOnlyTask;
import seedu.doit.model.tag.UniqueTagList;

/**
 * Provides a handle to a task card in the task list panel.
 */
public class TaskCardHandle extends GuiHandle {
    private static final String NAME_FIELD_ID = "#name";
    private static final String DESCRIPTION_FIELD_ID = "#description";
    private static final String DEADLINE_FIELD_ID = "#deadline";
    private static final String TAGS_FIELD_ID = "#tags";

    private Node node;

    public TaskCardHandle(GuiRobot guiRobot, Stage primaryStage, Node node) {
        super(guiRobot, primaryStage, null);
        this.node = node;
    }

    protected String getTextFromLabel(String fieldId) {
        return getTextFromLabel(fieldId, this.node);
    }

    public String getFullName() {
        return getTextFromLabel(NAME_FIELD_ID);
    }

    public String getDescription() {
        return getTextFromLabel(DESCRIPTION_FIELD_ID);
    }

    public String getDeadline() {
        return getTextFromLabel(DEADLINE_FIELD_ID);
    }


    public List<String> getTags() {
        return getTags(getTagsContainer());
    }

    private List<String> getTags(Region tagsContainer) {
        return tagsContainer
            .getChildrenUnmodifiable()
            .stream()
            .map(node -> ((Labeled) node).getText())
            .collect(Collectors.toList());
    }

    private List<String> getTags(UniqueTagList tags) {
        return tags
            .asObservableList()
            .stream()
            .map(tag -> tag.tagName)
            .collect(Collectors.toList());
    }

    private Region getTagsContainer() {
        return this.guiRobot.from(this.node).lookup(TAGS_FIELD_ID).query();
    }

    public boolean isSameTask(ReadOnlyTask task) {
        return getFullName().equals(task.getName().fullName)
            && getDescription().equals(task.getDescription().value);
    }



    @Override
    public boolean equals(Object obj) {
        if (obj instanceof TaskCardHandle) {
            TaskCardHandle handle = (TaskCardHandle) obj;
            return getFullName().equals(handle.getFullName())
                && getDeadline().equals(handle.getDeadline())
                && getDescription().equals(handle.getDescription())
                && getTags().equals(handle.getTags());
        }
        return super.equals(obj);
    }

    @Override
    public String toString() {
        return getFullName() + " " + getDescription();
    }
  //@@author
}

@@ -520,79 +520,8 @@
 e%22;%0A
-    private static final String DESCRIPTION_FIELD_ID = %22#description%22;%0A
     
@@ -577,24 +577,24 @@
 #deadline%22;%0A
+
     private 
@@ -1028,107 +1028,8 @@
  %7D%0A%0A
-    public String getDescription() %7B%0A        return getTextFromLabel(DESCRIPTION_FIELD_ID);%0A    %7D%0A%0A
     
@@ -1117,17 +1117,16 @@
 %0A    %7D%0A%0A
-%0A
     publ
@@ -1908,76 +1908,8 @@
 ame)
-%0A            && getDescription().equals(task.getDescription().value)
 ;%0A  
@@ -1913,18 +1913,16 @@
 %0A    %7D%0A%0A
-%0A%0A
     @Ove
@@ -2198,76 +2198,8 @@
 ())%0A
-                && getDescription().equals(handle.getDescription())%0A
     
@@ -2341,24 +2341,24 @@
 oString() %7B%0A
+
         retu
@@ -2377,33 +2377,8 @@
 me()
- + %22 %22 + getDescription()
 ;%0A  

Fix errors