package seedu.address.model;

import java.util.function.Predicate;
import java.util.logging.Logger;

import javafx.collections.transformation.FilteredList;
import seedu.address.commons.core.ComponentManager;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.core.UnmodifiableObservableList;
import seedu.address.commons.events.model.TaskBookChangedEvent;
import seedu.address.model.task.Task;
import seedu.address.model.task.TaskNotFoundException;

/**
 * Represents the in-memory model of the address book data.
 * All changes to any model should be synchronized.
 */
public class ModelManager extends ComponentManager implements Model {
    private static final Logger logger = LogsCenter.getLogger(ModelManager.class);

    private final TaskBook addressBook;
    private final FilteredList<Task> filteredTasks;

    /**
     * Initializes a ModelManager with the given TaskBook
     * TaskBook and its variables should not be null
     */
    public ModelManager(TaskBook src) {
        super();
        assert src != null;

        logger.fine("Initializing with address book: " + src);

        addressBook = new TaskBook(src);
        filteredTasks = new FilteredList<>(addressBook.getTasks());
    }

    public ModelManager() {
        this(new TaskBook());
    }

    public ModelManager(ReadOnlyTaskBook initialData) {
        addressBook = new TaskBook(initialData);
        filteredTasks = new FilteredList<>(addressBook.getTasks());
    }

    @Override
    public void resetData(ReadOnlyTaskBook newData) {
        addressBook.resetData(newData);
        indicateAddressBookChanged();
    }

    @Override
    public ReadOnlyTaskBook getAddressBook() {
        return addressBook;
    }

    /** Raises an event to indicate the model has changed */
    private void indicateAddressBookChanged() {
        raise(new TaskBookChangedEvent(addressBook));
    }

    @Override
    public synchronized void deleteTask(Task target) throws TaskNotFoundException {
        addressBook.removeTask(target);
        indicateAddressBookChanged();
    }

    @Override
    public synchronized void addTask(Task person) {
        addressBook.addTask(person);
        setFilter(null);
        indicateAddressBookChanged();
    }

    //=========== Filtered Task List Accessors ===============================================================

    @Override
    public UnmodifiableObservableList<Task> getFilteredTaskList() {
        return new UnmodifiableObservableList<>(filteredTasks);
    }

    @Override
    public void setFilter(Predicate<Task> predicate) {
        filteredTasks.setPredicate(predicate);
    }

}

@@ -768,23 +768,20 @@
 askBook 
-address
+task
 Book;%0A  
@@ -982,16 +982,24 @@
 Manager(
+ReadOnly
 TaskBook
@@ -999,19 +999,24 @@
 askBook 
-src
+taskBook
 ) %7B%0A    
@@ -1043,19 +1043,24 @@
  assert 
-src
+taskBook
  != null
@@ -1101,23 +1101,20 @@
 ng with 
-address
+task
  book: %22
@@ -1116,19 +1116,24 @@
 ok: %22 + 
-src
+taskBook
 );%0A%0A    
@@ -1128,39 +1128,41 @@
 Book);%0A%0A        
-address
+this.task
 Book = new TaskB
@@ -1169,11 +1169,16 @@
 ook(
-src
+taskBook
 );%0A 
@@ -1176,32 +1176,37 @@
 kBook);%0A        
+this.
 filteredTasks = 
@@ -1216,39 +1216,41 @@
  FilteredList%3C%3E(
-address
+this.task
 Book.getTasks())
@@ -1327,188 +1327,8 @@
  %7D%0A%0A
-    public ModelManager(ReadOnlyTaskBook initialData) %7B%0A        addressBook = new TaskBook(initialData);%0A        filteredTasks = new FilteredList%3C%3E(addressBook.getTasks());%0A    %7D%0A%0A
     
@@ -1395,31 +1395,28 @@
 ) %7B%0A        
-address
+task
 Book.resetDa
@@ -1436,39 +1436,36 @@
         indicate
-Address
+Task
 BookChanged();%0A 
@@ -1546,23 +1546,20 @@
  return 
-address
+task
 Book;%0A  
@@ -1641,39 +1641,36 @@
 te void indicate
-Address
+Task
 BookChanged() %7B%0A
@@ -1708,23 +1708,20 @@
 edEvent(
-address
+task
 Book));%0A
@@ -1829,31 +1829,28 @@
 n %7B%0A        
-address
+task
 Book.removeT
@@ -1870,39 +1870,36 @@
         indicate
-Address
+Task
 BookChanged();%0A 
@@ -1978,23 +1978,20 @@
         
-address
+task
 Book.add
@@ -2045,23 +2045,20 @@
 indicate
-Address
+Task
 BookChan

rename variables and methods