package seedu.task;

import javafx.stage.Screen;
import javafx.stage.Stage;
import seedu.task.MainApp;
import seedu.task.commons.core.Config;
import seedu.task.commons.core.GuiSettings;
import seedu.task.model.ReadOnlyTaskManager;
import seedu.task.model.UserPrefs;
import seedu.task.storage.XmlSerializableTaskManager;
import seedu.task.testutil.TestUtil;

import java.util.function.Supplier;

/**
 * This class is meant to override some properties of MainApp so that it will be suited for
 * testing
 */
public class TestApp extends MainApp {

    public static final String SAVE_LOCATION_FOR_TESTING = TestUtil.getFilePathInSandboxFolder("sampleData.xml");
    protected static final String DEFAULT_PREF_FILE_LOCATION_FOR_TESTING = TestUtil.getFilePathInSandboxFolder("pref_testing.json");
    public static final String APP_TITLE = "Test App";
    protected static final String TASK_MANAGER_NAME = "Test";
    protected Supplier<ReadOnlyTaskManager> initialDataSupplier = () -> null;
    protected String saveFileLocation = SAVE_LOCATION_FOR_TESTING;

    public TestApp() {
    }

    public TestApp(Supplier<ReadOnlyTaskManager> initialDataSupplier, String saveFileLocation) {
        super();
        this.initialDataSupplier = initialDataSupplier;
        this.saveFileLocation = saveFileLocation;

        // If some initial local data has been provided, write those to the file
        if (initialDataSupplier.get() != null) {
            TestUtil.createDataFileWithData(
                    new XmlSerializableTaskManager(this.initialDataSupplier.get()),
                    this.saveFileLocation);
        }
    }

    @Override
    protected Config initConfig(String configFilePath) {
        Config config = super.initConfig(configFilePath);
        config.setAppTitle(APP_TITLE);
        config.setTaskManagerFilePath(saveFileLocation);
        config.setUserPrefsFilePath(DEFAULT_PREF_FILE_LOCATION_FOR_TESTING);
        config.setTaskManagerName(TASK_MANAGER_NAME);
        config.setsortPreference("None");
        return config;
    }

    @Override
    protected UserPrefs initPrefs(Config config) {
        UserPrefs userPrefs = super.initPrefs(config);
        double x = Screen.getPrimary().getVisualBounds().getMinX();
        double y = Screen.getPrimary().getVisualBounds().getMinY();
        userPrefs.updateLastUsedGuiSetting(new GuiSettings(600.0, 600.0, (int) x, (int) y));
        return userPrefs;
    }


    @Override
    public void start(Stage primaryStage) {
        ui.start(primaryStage);
    }

    public static void main(String[] args) {
        launch(args);
    }
}

@@ -179,16 +179,59 @@
 ttings;%0A
+import seedu.task.commons.util.ConfigUtil;%0A
 import s
@@ -259,32 +259,32 @@
 nlyTaskManager;%0A
-
 import seedu.tas
@@ -394,16 +394,44 @@
 tUtil;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -543,16 +543,19 @@
  will be
+%0A *
  suited 
@@ -557,19 +557,16 @@
 ited for
-%0A *
  testing
@@ -799,32 +799,45 @@
 STING = TestUtil
+%0A            
 .getFilePathInSa
@@ -1558,37 +1558,16 @@
 ithData(
-%0A                    
 new XmlS
@@ -1675,32 +1675,58 @@
        %7D%0A    %7D%0A%0A
+    // @@author A0147944U%0A
     @Override%0A  
@@ -2103,24 +2103,173 @@
 ce(%22None%22);%0A
+        try %7B%0A            ConfigUtil.saveConfig(config, %22config.json%22);%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D%0A
         retu
@@ -2280,24 +2280,40 @@
 onfig;%0A    %7D
+%0A    // @@author
 %0A%0A    @Overr
@@ -2681,16 +2681,15 @@
 fs;%0A
+
     %7D%0A%0A
-%0A
     

fix TestApp.java to actually save config