// Path: src/main/java/com/rapid7/appspider/datatransferobjects/ScanResult.java
// public class ScanResult {
//     private final boolean isSuccess;
//     private final String scanId;
// 
//     public ScanResult(boolean isSuccess, String scanId) {
//         this.isSuccess = isSuccess;
//         this.scanId = scanId;
//     }
//     public ScanResult(JSONObject jsonObject) {
//         if (jsonObject == null)
//             throw new IllegalArgumentException("jsonObject cannot be null");
// 
//         try {
//             isSuccess = jsonObject.getBoolean("IsSuccess");
//             scanId = jsonObject.getJSONObject("Scan").getString("Id");
// 
//         } catch(JSONException e) {
//             throw new IllegalArgumentException("unexpected error occured parsing scan result", e);
//         }
// 
//     }
// 
//     public String getScanId() {
//         return scanId;
//     }
// 
//     public boolean isSuccess() {
//         return isSuccess;
//     }
// }
// 
// Path: src/main/java/com/rapid7/appspider/models/AuthenticationModel.java
// public class AuthenticationModel {
// 
//     private final String username;
//     private final String password;
//     private final Optional<String> clientId;
// 
//     /**
//      * instantiates a new instance of the {@code AuthenticationModel} class with no client Id
//      */
//     public AuthenticationModel(String username, String password) {
//         this(username, password, Optional.empty());
//     }
// 
//     /**
//      * instantiates a new instance of the {@code AuthenticationModel} class ensuring that
//      * username and password are both non-null and non-empty
//      */
//     public AuthenticationModel(String username, String password, Optional<String> clientId) {
//         if (username == null || username.isEmpty() || password == null || password.isEmpty()) {
//             throw new IllegalArgumentException();
//         }
//         this.username = username;
//         this.password = password;
//         this.clientId = clientId;
//     }
// 
//     /**
//      * gets the password value
//      * @return password as a {@code Secret}
//      */
//     public String getPassword() {
//         return password;
//     }
// 
//     /**
//      * Get the username value
//      * @return username as a String
//      */
//     public String getUsername() {
//         return username;
//     }
// 
//     /**
//      * Returns whether this object contains a clientId or not
//      * 
//      * <p>
//      * should be called prior to {@code getClientId} to ensure a value is present,
//      * otherwise an exception may occur
//      * </p>
//      * @return true if client id is set; otherwise, false
//      */
//     public boolean hasClientId() {
//         return clientId.isPresent();
//     }
// 
//     /**
//      * Gets the client id if present; otherwise throws a {@code NoSuchElementException}
//      * @return the client Id if present
//      * @throws NoSuchElementException if this instance does not have a clientId
//      */
//     public String getClientId() throws NoSuchElementException {
//         return clientId.orElseThrow(NoSuchElementException::new);
//     }
// 
// 
// }


import com.rapid7.appspider.datatransferobjects.ScanResult;
import com.rapid7.appspider.models.AuthenticationModel;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
        final boolean isNewConfig = (!(Objects.isNull(newConfigName) || newConfigName.isEmpty()) && !(Objects.isNull(newConfigUrl) || newConfigUrl.isEmpty()));
        if (!isNewConfig) // local not really needed but is provided to clarify the meaning of these conditions
            return true; // creation not needed

        log.println("Value of Scan Config Name: " + newConfigName);
        log.println("Value of Scan Config URL: " + newConfigUrl);
        log.println("Value of Scan Config Engine Group name: " + settings.getScanConfigEngineGroupName());

        Optional<String> engineGroupId = client.getEngineGroupIdFromName(authToken, settings.getScanConfigEngineGroupName());
        if (!engineGroupId.isPresent()) {
            log.println(String.format("no engine group matching %s was found.", settings.getScanConfigEngineGroupName()));
            return false;
        }

        URL newScanConfigTarget;
        try {
            newScanConfigTarget = new URL(newConfigUrl);
        } catch (MalformedURLException e) {
            log.println(String.format("Invalid scan targat '%s', unable to save configuration", newConfigUrl));
            log.severe(e.getMessage());
            return false;
        }

        if  (client.saveConfig(authToken, newConfigName, newScanConfigTarget, engineGroupId.get())) {
            settings.setConfigName(settings.getNewConfigName());
            log.println(String.format("Successfully created the scan config %s", newConfigName));

            settings.resetNewConfigValues();
            return true;
        } else {
// Path: src/main/java/com/rapid7/appspider/datatransferobjects/ScanResult.java
// public class ScanResult {
//     private final boolean isSuccess;
//     private final String scanId;
// 
//     public ScanResult(boolean isSuccess, String scanId) {
//         this.isSuccess = isSuccess;
//         this.scanId = scanId;
//     }
//     public ScanResult(JSONObject jsonObject) {
//         if (jsonObject == null)
//             throw new IllegalArgumentException("jsonObject cannot be null");
// 
//         try {
//             isSuccess = jsonObject.getBoolean("IsSuccess");
//             scanId = jsonObject.getJSONObject("Scan").getString("Id");
// 
//         } catch(JSONException e) {
//             throw new IllegalArgumentException("unexpected error occured parsing scan result", e);
//         }
// 
//     }
// 
//     public String getScanId() {
//         return scanId;
//     }
// 
//     public boolean isSuccess() {
//         return isSuccess;
//     }
// }
// 
// Path: src/main/java/com/rapid7/appspider/models/AuthenticationModel.java
// public class AuthenticationModel {
// 
//     private final String username;
//     private final String password;
//     private final Optional<String> clientId;
// 
//     /**
//      * instantiates a new instance of the {@code AuthenticationModel} class with no client Id
//      */
//     public AuthenticationModel(String username, String password) {
//         this(username, password, Optional.empty());
//     }
// 
//     /**
//      * instantiates a new instance of the {@code AuthenticationModel} class ensuring that
//      * username and password are both non-null and non-empty
//      */
//     public AuthenticationModel(String username, String password, Optional<String> clientId) {
//         if (username == null || username.isEmpty() || password == null || password.isEmpty()) {
//             throw new IllegalArgumentException();
//         }
//         this.username = username;
//         this.password = password;
//         this.clientId = clientId;
//     }
// 
//     /**
//      * gets the password value
//      * @return password as a {@code Secret}
//      */
//     public String getPassword() {
//         return password;
//     }
// 
//     /**
//      * Get the username value
//      * @return username as a String
//      */
//     public String getUsername() {
//         return username;
//     }
// 
//     /**
//      * Returns whether this object contains a clientId or not
//      * 
//      * <p>
//      * should be called prior to {@code getClientId} to ensure a value is present,
//      * otherwise an exception may occur
//      * </p>
//      * @return true if client id is set; otherwise, false
//      */
//     public boolean hasClientId() {
//         return clientId.isPresent();
//     }
// 
//     /**
//      * Gets the client id if present; otherwise throws a {@code NoSuchElementException}
//      * @return the client Id if present
//      * @throws NoSuchElementException if this instance does not have a clientId
//      */
//     public String getClientId() throws NoSuchElementException {
//         return clientId.orElseThrow(NoSuchElementException::new);
//     }
// 
// 
// }


// Path: src/main/java/com/rapid7/appspider/Scan.java
import com.rapid7.appspider.datatransferobjects.ScanResult;
import com.rapid7.appspider.models.AuthenticationModel;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

        final boolean isNewConfig = (!(Objects.isNull(newConfigName) || newConfigName.isEmpty()) && !(Objects.isNull(newConfigUrl) || newConfigUrl.isEmpty()));
        if (!isNewConfig) // local not really needed but is provided to clarify the meaning of these conditions
            return true; // creation not needed

        log.println("Value of Scan Config Name: " + newConfigName);
        log.println("Value of Scan Config URL: " + newConfigUrl);
        log.println("Value of Scan Config Engine Group name: " + settings.getScanConfigEngineGroupName());

        Optional<String> engineGroupId = client.getEngineGroupIdFromName(authToken, settings.getScanConfigEngineGroupName());
        if (!engineGroupId.isPresent()) {
            log.println(String.format("no engine group matching %s was found.", settings.getScanConfigEngineGroupName()));
            return false;
        }

        URL newScanConfigTarget;
        try {
            newScanConfigTarget = new URL(newConfigUrl);
        } catch (MalformedURLException e) {
            log.println(String.format("Invalid scan targat '%s', unable to save configuration", newConfigUrl));
            log.severe(e.getMessage());
            return false;
        }

        if  (client.saveConfig(authToken, newConfigName, newScanConfigTarget, engineGroupId.get())) {
            settings.setConfigName(settings.getNewConfigName());
            log.println(String.format("Successfully created the scan config %s", newConfigName));

            settings.resetNewConfigValues();
            return true;
        } else {
            log.println(String.format("An error occurred while attempting to save %s.", newConfigName));