/*
 * Copyright (C) 2017 Reece H. Dunn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.co.reecedunn.intellij.plugin.execution.marklogic.configuration;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.*;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import uk.co.reecedunn.intellij.plugin.core.ui.SettingsEditorImpl;
import uk.co.reecedunn.intellij.plugin.core.ui.SettingsUI;
import uk.co.reecedunn.intellij.plugin.core.ui.SettingsUIFactory;
import uk.co.reecedunn.intellij.plugin.execution.marklogic.runner.MarkLogicRunProfileState;

public class MarkLogicRunConfiguration extends RunConfigurationBase implements SettingsUIFactory<MarkLogicRunConfiguration> {
    private String serverHost = "localhost";
    private int serverPort = 8000;
    private String userName = "";
    private String password = "";
    private String mainModulePath = "";

    MarkLogicRunConfiguration(@NotNull Project project, @NotNull ConfigurationFactory factory, String name) {
        super(project, factory, name);
    }

    @NotNull
    @Override
    public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
        return new SettingsEditorImpl<>(this);
    }

    @Override
    public void checkConfiguration() throws RuntimeConfigurationException {
    }

    @Nullable
    @Override
    public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
        return new MarkLogicRunProfileState(environment);
    }

    @Override
    public SettingsUI<MarkLogicRunConfiguration> createSettingsUI() {
        return new MarkLogicSettingsUI(getProject());
    }

    public String getServerHost() {
        return serverHost;
    }

    public void setServerHost(String host) {
        serverHost = host;
    }

    public int getServerPort() {
        return serverPort;
    }

    public void setServerPort(int port) {
        serverPort = port;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getMainModulePath() {
        return mainModulePath;
    }

    public void setMainModulePath(String mainModulePath) {
        this.mainModulePath = mainModulePath;
    }
}

@@ -961,16 +961,211 @@
 roject;%0A
+import com.intellij.openapi.util.DefaultJDOMExternalizer;%0Aimport com.intellij.openapi.util.InvalidDataException;%0Aimport com.intellij.openapi.util.WriteExternalException;%0Aimport org.jdom.Element;%0A
 import o
@@ -1198,16 +1198,16 @@
 otNull;%0A
-
 import o
@@ -1652,31 +1652,64 @@
 tion%3E %7B%0A    
-private
+static class ConfigData %7B%0A        public
  String serv
@@ -1734,23 +1734,26 @@
 t%22;%0A    
-private
+    public
  int ser
@@ -1768,31 +1768,34 @@
 = 8000;%0A    
+  
-private
+  public
  String user
@@ -1801,39 +1801,42 @@
 rName = %22%22;%0A    
-private
+    public
  String password
@@ -1850,15 +1850,18 @@
     
-private
+    public
  Str
@@ -1884,16 +1884,71 @@
 th = %22%22;
+%0A    %7D%0A%0A    private ConfigData data = new ConfigData();
 %0A%0A    Ma
@@ -2721,32 +2721,501 @@
 ject());%0A    %7D%0A%0A
+    @SuppressWarnings(%22deprecation%22)%0A    @Override%0A    public void readExternal(Element element) throws InvalidDataException %7B%0A        super.readExternal(element);%0A        DefaultJDOMExternalizer.readExternal(data, element);%0A    %7D%0A%0A    @SuppressWarnings(%22deprecation%22)%0A    @Override%0A    public void writeExternal(Element element) throws WriteExternalException %7B%0A        super.writeExternal(element);%0A        DefaultJDOMExternalizer.writeExternal(data, element);%0A    %7D%0A%0A
     public Strin
@@ -3245,24 +3245,29 @@
      return 
+data.
 serverHost;%0A
@@ -3322,24 +3322,29 @@
 ) %7B%0A        
+data.
 serverHost =
@@ -3405,16 +3405,21 @@
  return 
+data.
 serverPo
@@ -3479,16 +3479,21 @@
         
+data.
 serverPo
@@ -3559,16 +3559,21 @@
  return 
+data.
 userName
@@ -3641,16 +3641,21 @@
    this.
+data.
 userName
@@ -3723,16 +3723,21 @@
  return 
+data.
 password
@@ -3805,16 +3805,21 @@
    this.
+data.
 password
@@ -3893,16 +3893,21 @@
  return 
+data.
 mainModu
@@ -3976,24 +3976,24 @@
 dulePath) %7B%0A
-
         this
@@ -3993,16 +3993,21 @@
    this.
+data.
 mainModu

Implement persistence of the MarkLogicRunConfiguration data.