package seedu.jimi.storage;

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

import seedu.jimi.commons.core.LogsCenter;
import seedu.jimi.commons.exceptions.DataConversionException;
import seedu.jimi.commons.util.FileUtil;
import seedu.jimi.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 taskBookOptional = XmlFileStorage.loadDataFromSaveFile(new File(filePath));

        return Optional.of(taskBookOptional);
    }

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

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

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

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

@@ -808,24 +808,124 @@
  %7D%0A    %0A
+    public void setTaskBookFilePath(String filePath) %7B%0A        this.filePath = filePath;%0A    %7D%0A    %0A
     /**%0A
      * S
@@ -908,32 +908,32 @@
  %7D%0A    %0A    /**%0A
-
      * Similar t
@@ -1166,32 +1166,44 @@
 String filePath)
+%0A           
  throws DataConv
@@ -1268,33 +1268,41 @@
 lePath != null;%0A
+        
 %0A
-
         File add
@@ -1336,17 +1336,25 @@
 ePath);%0A
+        
 %0A
-
         
@@ -1426,17 +1426,16 @@
 k file %22
- 
  + addre
@@ -1505,25 +1505,33 @@
 ;%0A        %7D%0A
+        
 %0A
-
         Read
@@ -1619,17 +1619,25 @@
 Path));%0A
+        
 %0A
-
         
@@ -1676,25 +1676,29 @@
 nal);%0A    %7D%0A
+    
 %0A
-
     /**%0A    
@@ -1979,17 +1979,25 @@
 = null;%0A
+        
 %0A
-
         
@@ -2150,33 +2150,37 @@
 skBook));%0A    %7D%0A
+    
 %0A
-
     @Override%0A  
@@ -2321,17 +2321,21 @@
 ;%0A    %7D%0A
+    
 %0A
-
     @Ove
@@ -2459,16 +2459,21 @@
 ePath);%0A
-
     %7D%0A
+    %0A
 %7D%0A

format and add filepath setter method