package seedu.todo.controllers;

import seedu.todo.commons.EphemeralDB;
import seedu.todo.models.CalendarItem;
import seedu.todo.models.Event;
import seedu.todo.models.Task;
import seedu.todo.models.TodoListDB;
import seedu.todo.ui.UiManager;
import seedu.todo.ui.views.IndexView;

public class DestroyController implements Controller {
    
    private static String NAME = "Destroy";
    private static String DESCRIPTION = "Destroys a task/event by listed index";
    private static String COMMAND_SYNTAX = "destroy <index>";
    
    private static CommandDefinition commandDefinition =
            new CommandDefinition(NAME, DESCRIPTION, COMMAND_SYNTAX); 

    public static CommandDefinition getCommandDefinition() {
        return commandDefinition;
    }

    @Override
    public float inputConfidence(String input) {
        // TODO
        return (input.startsWith("delete") || input.startsWith("destroy")) || input.startsWith("remove") ? 1 : 0;
    }

    @Override
    public void process(String args) {
        // TODO: Example of last minute work
        
        // Get index.
        int index = Integer.decode(args.replaceFirst("(delete|destroy|remove)", "").trim());
        
        // Get record
        EphemeralDB edb = EphemeralDB.getInstance();
        CalendarItem calendarItem = edb.getCalendarItemsByDisplayedId(index);
        TodoListDB db = TodoListDB.getInstance();
        
        if (calendarItem != null) {
            if (calendarItem instanceof Task) {
                db.destroyTask((Task) calendarItem);
            } else {
                db.destroyEvent((Event) calendarItem);
            }
        }
        
        // Re-render
        IndexView view = UiManager.loadView(IndexView.class);
        view.tasks = db.getAllTasks();
        view.events = db.getAllEvents();
        UiManager.renderView(view);
    }

}

@@ -523,24 +523,253 @@
 dex%3E%22;%0A    %0A
+    private static String MESSAGE_DELETE_SUCCESS = %22Item deleted successfully!%5Cn%22 + %22To undo, type %5C%22undo%5C%22.%22;%0A    private static String MESSAGE_INVALID_CALENDARITEM = %22Could not delete task/event: invalid index provided!%22;%0A    %0A
     private 
@@ -1655,17 +1655,17 @@
 darItem 
-!
+=
 = null) 
@@ -1662,32 +1662,187 @@
  == null) %7B%0A    
+        UiManager.updateConsoleMessage(MESSAGE_INVALID_CALENDARITEM);%0A            return;%0A        %7D%0A        %0A        assert calendarItem != null;%0A        %0A
         if (cale
@@ -1865,28 +1865,24 @@
 eof Task) %7B%0A
-    
             
@@ -1926,20 +1926,16 @@
         
-    
 %7D else %7B
@@ -1935,20 +1935,16 @@
  else %7B%0A
-    
         
@@ -1990,22 +1990,8 @@
 m);%0A
-            %7D%0A
     
@@ -2164,24 +2164,24 @@
 llEvents();%0A
-
         UiMa
@@ -2204,16 +2204,121 @@
 (view);%0A
+        %0A        // Show console message%0A        UiManager.updateConsoleMessage(MESSAGE_DELETE_SUCCESS);%0A
     %7D%0A%0A%7D

Add error message for DestroyController