package seedu.taskmanager.storage;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Optional;
import java.util.logging.Logger;

import seedu.taskmanager.commons.core.LogsCenter;
import seedu.taskmanager.commons.exceptions.DataConversionException;
import seedu.taskmanager.commons.util.FileUtil;
import seedu.taskmanager.model.ReadOnlyTaskManager;

/**
 * A class to access AddressBook data stored as an xml file on the hard disk.
 */
public class XmlTaskManagerStorage implements TaskManagerStorage {

    private static final Logger logger = LogsCenter.getLogger(XmlTaskManagerStorage.class);

    private String filePath;

    public XmlTaskManagerStorage(String filePath) {
        this.filePath = filePath;
    }

    public String getTaskManagerFilePath() {
        return filePath;
    }

    @Override
    public Optional<ReadOnlyTaskManager> readTaskManager() throws DataConversionException, IOException {
        return readTaskManager(filePath);
    }

    /**
     * Similar to {@link #readTaskManager()}
     * @param filePath location of the data. Cannot be null
     * @throws DataConversionException if the file is not in the correct format.
     */
    public Optional<ReadOnlyTaskManager> readTaskManager(String filePath) throws DataConversionException,
                                                                                 FileNotFoundException {
        assert filePath != null;

        File addressBookFile = new File(filePath);

        if (!addressBookFile.exists()) {
            logger.info("AddressBook file "  + addressBookFile + " not found");
            return Optional.empty();
        }

        ReadOnlyTaskManager addressBookOptional = XmlFileStorage.loadDataFromSaveFile(new File(filePath));

        return Optional.of(addressBookOptional);
    }

    @Override
    public void saveTaskManager(ReadOnlyTaskManager addressBook) throws IOException {
        saveTaskManager(addressBook, filePath);
    }

    /**
     * Similar to {@link #saveTaskManager(ReadOnlyTaskManager)}
     * @param filePath location of the data. Cannot be null
     */
    public void saveTaskManager(ReadOnlyTaskManager addressBook, String filePath) throws IOException {
        assert addressBook != null;
        assert filePath != null;

        File file = new File(filePath);
        FileUtil.createIfMissing(file);
        XmlFileStorage.saveDataToFile(file, new XmlSerializableTaskManager(addressBook));
    }

}

@@ -422,27 +422,27 @@
  access 
-AddressBook
+TaskManager
  data st
@@ -1472,27 +1472,27 @@
    File 
-addressBook
+taskManager
 File = n
@@ -1524,27 +1524,27 @@
    if (!
-addressBook
+taskManager
 File.exi
@@ -1581,41 +1581,41 @@
 fo(%22
-AddressBook file %22  + addressBook
+TaskManager file %22  + taskManager
 File
@@ -1708,27 +1708,27 @@
 Manager 
-addressBook
+taskManager
 Optional
@@ -1815,27 +1815,27 @@
 onal.of(
-addressBook
+taskManager
 Optional
@@ -1910,27 +1910,27 @@
 Manager 
-addressBook
+taskManager
 ) throws
@@ -1968,27 +1968,27 @@
 Manager(
-addressBook
+taskManager
 , filePa
@@ -2191,27 +2191,27 @@
 Manager 
-addressBook
+taskManager
 , String
@@ -2257,27 +2257,27 @@
  assert 
-addressBook
+taskManager
  != null
@@ -2471,19 +2471,19 @@
 ger(
-addressBook
+taskManager
 ));%0A

Refactor XmlTaskManagerStorage