package seedu.address.storage;

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

import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.exceptions.DataConversionException;
import seedu.address.commons.util.FileUtil;
import seedu.address.model.ReadOnlyTaskBook;

/**
 * A class to access TaskBook data stored as an xml file on the hard disk.
 */
public class XmlTaskBookStorage implements TaskBookStorage {

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

    private String filePath;

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

    public String getTaskBookFilePath() {
        return filePath;
    }

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

        File addressBookFile = new File(filePath);

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

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

        return Optional.of(addressBookOptional);
    }

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

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

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

    @Override
    public void saveTaskBook(ReadOnlyTaskBook addressBook) throws IOException {
        saveTaskBook(addressBook, filePath);
    }
}

@@ -1173,23 +1173,20 @@
    File 
-address
+task
 BookFile
@@ -1222,23 +1222,20 @@
    if (!
-address
+task
 BookFile
@@ -1290,23 +1290,20 @@
 ile %22 + 
-address
+task
 BookFile
@@ -1389,31 +1389,28 @@
 nlyTaskBook 
-address
+task
 BookOptional
@@ -1497,23 +1497,20 @@
 onal.of(
-address
+task
 BookOpti
@@ -1858,31 +1858,28 @@
 nlyTaskBook 
-address
+task
 Book, String
@@ -1925,23 +1925,20 @@
  assert 
-address
+task
 Book != 
@@ -2125,31 +2125,28 @@
 bleTaskBook(
-address
+task
 Book));%0A    
@@ -2208,23 +2208,20 @@
 askBook 
-address
+task
 Book) th
@@ -2260,23 +2260,20 @@
 askBook(
-address
+task
 Book, fi

correct variable names