// Path: cassandra-migration/src/main/java/org/cognitor/cassandra/migration/util/Ensure.java
// public static String notNullOrEmpty(String argument, String argumentName) {
//     if (argument == null || argument.trim().isEmpty()) {
//         throw new IllegalArgumentException("Argument " + argumentName + " must not be null or empty.");
//     }
//     return argument;
// }


import java.util.HashMap;
import java.util.Map;
import static java.lang.String.join;
import static java.util.Collections.unmodifiableMap;
import static java.util.stream.Collectors.toSet;
import static org.cognitor.cassandra.migration.util.Ensure.notNullOrEmpty;
package org.cognitor.cassandra.migration.keyspace;



/**
 * @author Patrick Kranz
 */
public class NetworkStrategy implements ReplicationStrategy {
    private final Map<String, Integer> dataCenters = new HashMap<>();

    @Override
    public String getName() {
        return "NetworkTopologyStrategy";
    }

    @Override
    public String createCqlStatement() {
        if (getDataCenters().isEmpty()) {
            throw new IllegalStateException("There has to be at least one datacenter in order to use NetworkTopologyStrategy.");
        }

        StringBuilder builder = new StringBuilder();
        builder.append("{")
                .append("'class':'").append(getName()).append("',");

        builder.append(join(",",
                dataCenters.keySet().stream().map(dc -> "'" + dc + "':" + dataCenters.get(dc))
                        .collect(toSet())));
        builder.append("}");
        return builder.toString();
    }

    public NetworkStrategy with(String datacenter, int replicationFactor) {
// Path: cassandra-migration/src/main/java/org/cognitor/cassandra/migration/util/Ensure.java
// public static String notNullOrEmpty(String argument, String argumentName) {
//     if (argument == null || argument.trim().isEmpty()) {
//         throw new IllegalArgumentException("Argument " + argumentName + " must not be null or empty.");
//     }
//     return argument;
// }


// Path: cassandra-migration/src/main/java/org/cognitor/cassandra/migration/keyspace/NetworkStrategy.java
import java.util.HashMap;
import java.util.Map;
import static java.lang.String.join;
import static java.util.Collections.unmodifiableMap;
import static java.util.stream.Collectors.toSet;
import static org.cognitor.cassandra.migration.util.Ensure.notNullOrEmpty;

package org.cognitor.cassandra.migration.keyspace;



/**
 * @author Patrick Kranz
 */
public class NetworkStrategy implements ReplicationStrategy {
    private final Map<String, Integer> dataCenters = new HashMap<>();

    @Override
    public String getName() {
        return "NetworkTopologyStrategy";
    }

    @Override
    public String createCqlStatement() {
        if (getDataCenters().isEmpty()) {
            throw new IllegalStateException("There has to be at least one datacenter in order to use NetworkTopologyStrategy.");
        }

        StringBuilder builder = new StringBuilder();
        builder.append("{")
                .append("'class':'").append(getName()).append("',");

        builder.append(join(",",
                dataCenters.keySet().stream().map(dc -> "'" + dc + "':" + dataCenters.get(dc))
                        .collect(toSet())));
        builder.append("}");
        return builder.toString();
    }

    public NetworkStrategy with(String datacenter, int replicationFactor) {
        notNullOrEmpty(datacenter, "datacenter");