package tars.logic.commands;

import java.time.DateTimeException;
import java.util.HashSet;
import java.util.Set;

import tars.commons.core.Messages;
import tars.commons.exceptions.DuplicateTaskException;
import tars.commons.exceptions.IllegalValueException;
import tars.model.task.DateTime;
import tars.model.task.Name;
import tars.model.task.Priority;
import tars.model.task.rsv.RsvTask;

/**
 * Adds a reserved task which has a list of reserved datetimes that can
 * confirmed later on.
 * 
 * @@author A0124333U
 */

public class RsvCommand extends UndoableCommand {

    public static final String COMMAND_WORD = "rsv";

    public static final String MESSAGE_USAGE = COMMAND_WORD + ": Reserves one or more timeslot for a task.\n"
            + "Parameters: TASK [-dt DATETIME] [ADDITIONAL DATETIME]\n" + "Example: " + COMMAND_WORD
            + " Meet John Doe -dt 26/09/2016 0900 to 1030, 28/09/2016 1000 to 1130";
    
    public static final String MESSAGE_DATETIME_NOTFOUND = "At least one DateTime is required!\n" + MESSAGE_USAGE;

    public static final String MESSAGE_SUCCESS = "New task reserved: %1$s";
    public static final String MESSAGE_UNDO = "Removed %1$s";
    public static final String MESSAGE_REDO = "Reserved %1$s";

    private final RsvTask toReserve;

    /**
     * Convenience constructor using raw values.
     *
     * @throws IllegalValueException
     *             if any of the raw values are invalid
     * @throws DateTimeException
     *             if given dateTime string is invalid.
     */

    public RsvCommand(String name, Set<String[]> dateTimeStringSet, String priority, Set<String> tags)
            throws IllegalValueException {

        Set<DateTime> dateTimeSet = new HashSet<>();
        for (String[] dateTimeStringArray : dateTimeStringSet) {
            dateTimeSet.add(new DateTime(dateTimeStringArray[0], dateTimeStringArray[1]));
        }

        this.toReserve = new RsvTask(new Name(name), dateTimeSet, new Priority(priority), new HashSet<String>(tags));

    }

    @Override
    public CommandResult undo() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public CommandResult redo() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public CommandResult execute() {
        assert model != null;
        try {
            model.addRsvTask(toReserve);
            model.getUndoableCmdHist().push(this);
            return new CommandResult(String.format(MESSAGE_SUCCESS, toReserve.toString()));
        } catch (DuplicateTaskException e) {
            return new CommandResult(Messages.MESSAGE_DUPLICATE_TASK);
        }

    }

}


@@ -55,24 +55,52 @@
 eException;%0A
+import java.util.ArrayList;%0A
 import java.
@@ -645,16 +645,137 @@
 = %22rsv%22;
+%0A    public static final String COMMAND_WORD_DEL = %22rsv -d%22;%0A    public static final String COMMAND_WORD_EDIT = %22rsv -e%22;
 %0A%0A    pu
@@ -1068,196 +1068,695 @@
 0%22;%0A
+%0A
     
-%0A    public static final String MESSAGE_DATETIME_NOTFOUND = %22At least one DateTime is required!%5Cn%22 + MESSAGE_USAGE;%0A%0A    public static final String MESSAGE_SUCCESS = %22New task reserved
+public static final String MESSAGE_USAGE_DEL = COMMAND_WORD_DEL%0A            + %22: Deletes a reserved task in the last reserved task listing %5Cn%22%0A            + %22Parameters: INDEX (must be a positive integer)%5Cn %22 + %22Example: %22 + COMMAND_WORD_DEL + %22 1%5Cn%22 + %22OR %22%0A            + COMMAND_WORD_DEL + %22 1..3%22;%0A%0A    public static final String MESSAGE_DATETIME_NOTFOUND = %22At least one DateTime is required!%5Cn%22 + MESSAGE_USAGE;%0A    %0A    public static final String MESSAGE_DEL_AND_EDIT_FLAG_DETECTED = %22Both Delete and Edit Flag detected!%22;%0A%0A    public static final String MESSAGE_SUCCESS = %22New task reserved: %251$s%22;%0A    public static final String MESSAGE_SUCCESS_DEL = %22Deleted Reserved Tasks
 : %251
@@ -1898,22 +1898,16 @@
 private 
-final 
 RsvTask 
@@ -1915,16 +1915,65 @@
 oReserve
+ = null;%0A    private String rangeIndexString = %22%22
 ;%0A%0A    /
@@ -2707,32 +2707,138 @@
 tags));%0A%0A    %7D%0A%0A
+    public RsvCommand(String rangeIndexString) %7B%0A        this.rangeIndexString = rangeIndexString;%0A    %7D%0A%0A
     @Override%0A  
@@ -3136,24 +3136,62 @@
 el != null;%0A
+%0A        if (toReserve != null) %7B%0A    
         try 
@@ -3192,16 +3192,20 @@
   try %7B%0A
+    
         
@@ -3245,24 +3245,28 @@
             
+    
 model.getUnd
@@ -3292,16 +3292,20 @@
 (this);%0A
+    
         
@@ -3396,16 +3396,20 @@
         
+    
 %7D catch 
@@ -3433,24 +3433,28 @@
 eption e) %7B%0A
+    
             
@@ -3512,16 +3512,221 @@
 _TASK);%0A
+            %7D%0A        %7D else %7B%0A            ArrayList%3CRsvTask%3E tasksToDelete = new ArrayList%3CRsvTask%3E();%0A%0A            return new CommandResult(String.format(MESSAGE_SUCCESS_DEL, tasksToDelete.toString()));%0A
         
@@ -3737,9 +3737,8 @@
    %7D%0A%0A%7D%0A
-%0A

Add Rsv Del method in RsvCommand