package seedu.oneline.logic.commands;

import javafx.collections.transformation.FilteredList;
import seedu.oneline.commons.core.UnmodifiableObservableList;
import seedu.oneline.commons.exceptions.IllegalValueException;
import seedu.oneline.model.tag.Tag;
import seedu.oneline.model.task.ReadOnlyTask;

public class DeleteTagCommand extends DeleteCommand {

    private final String tagName;
    
    public DeleteTagCommand(String tagName) {
        this.tagName = tagName;
    }
    
    public static DeleteTagCommand createFromArgs(String args) throws IllegalValueException {
        String tagName = args.substring(1);
        if (!Tag.isValidTagName(tagName)) {
            throw new IllegalValueException(Tag.MESSAGE_TAG_CONSTRAINTS + " : " + args);
        } else {
            return new DeleteTagCommand(tagName);
        }
    }
    
    @Override
    public CommandResult execute() {
        FilteredList<Tag> tagList = model.getTagList().filtered(tag -> tag.getTagName().equals(tagName));
        if (tagList.isEmpty()){
            return new CommandResult(String.format(Tag.MESSAGE_INVALID_TAG, tagName));
        } else {
            // TODO
            return new CommandResult(MESSAGE_DELETE_CAT_SUCCESS + " : " + tagName);
        }
    }
    
    @Override
    public boolean canUndo() {
        return true;
    }
    
}

@@ -1,8 +1,29 @@
+//@@author A0138848M%0A
 package 
@@ -53,16 +53,40 @@
 mands;%0A%0A
+import java.util.List;%0A%0A
 import j
@@ -136,70 +136,8 @@
 st;%0A
-import seedu.oneline.commons.core.UnmodifiableObservableList;%0A
 impo
@@ -276,16 +276,102 @@
 nlyTask;
+%0Aimport seedu.oneline.model.task.Task;%0Aimport seedu.oneline.model.task.UniqueTaskList;
 %0A%0Apublic
@@ -898,32 +898,190 @@
    %7D%0A    %7D%0A    %0A
+    /**%0A     * Pre-condition: model.replaceTask removes the tag all together%0A     * as long as all tasks tagged with the tag have their tags removed.%0A     */%0A
     @Override%0A  
@@ -1376,12 +1376,893 @@
  // 
-TODO
+remove tags from tasks that are currently tagged %0A            // model.replaceTask handles removing the tag%0A            List%3CReadOnlyTask%3E taskWithTag = %0A                    model.getFilteredTaskList().filtered(task -%3E task.getTag().getTagName().equals(tagName));%0A            Tag defaultTag = Tag.getDefault();%0A            while (!taskWithTag.isEmpty())%7B%0A                ReadOnlyTask oldTask = taskWithTag.get(0);%0A                Task newTask = oldTask.updateTag(defaultTag);%0A                try %7B%0A                    model.replaceTask(oldTask, newTask);%0A                %7D catch (UniqueTaskList.TaskNotFoundException e) %7B%0A                    assert false : %22The target task cannot be missing%22;%0A                %7D catch (UniqueTaskList.DuplicateTaskException e) %7B%0A                    assert false : %22The update task should not already exist%22;%0A                %7D%0A            %7D%0A            
 %0A   
@@ -2295,16 +2295,30 @@
 dResult(
+String.format(
 MESSAGE_
@@ -2335,26 +2335,17 @@
 _SUCCESS
- + %22 : %22 +
+,
  tagName
@@ -2337,32 +2337,33 @@
 UCCESS, tagName)
+)
 ;%0A        %7D%0A    

Implement execute delete tag