import java.io.IOException;
import java.util.Properties;


class jmeterRunner {


    jmeterRunner() throws IOException {
    }

    static String generateJmeterCommand(String testName, Integer threads, Integer duration, Integer size, Properties props){

        String command =
                "jmeter"
                + " -n -t \"src\\main\\resources\\"
                + testName
                + "\""
                + " -Jthreads="
                + threads.toString()
                + " -Jduration="
                + duration.toString();

        if(testName.toUpperCase().contains("SOAP")){

            command += " -JSOAP_WebServerProtocol=" + props.getProperty("SOAP_WebServerProtocol")
                    + " -JSOAP_IP=" + props.getProperty("SOAP_IP")
                    + " -JSOAP_PortNumber=" + props.getProperty("SOAP_PortNumber")
                    + " -JSOAP_Path=" + props.getProperty("SOAP_Path");

            if (testName.toUpperCase().contains("GET")){
                command += " -JSOAP_size=" + size.toString();

            } else if(testName.toUpperCase().contains("ATTACHMENT")){
                String sendAttachmentURL =
                        props.getProperty("SOAP_WebServerProtocol")
                        + "://" + props.getProperty("SOAP_IP")
                        + ":" + props.getProperty("SOAP_PortNumber")
                        + "/" + props.getProperty("SOAP_Path");
                command += " -Jurl=" + sendAttachmentURL;
            }


        } else if (testName.toUpperCase().contains("REST")){

            command += " -JREST_WebServerProtocol=" + props.getProperty("REST_WebServerProtocol")
                    + " -JREST_IP=" + props.getProperty("REST_IP")
                    + " -JREST_PortNumber=" + props.getProperty("REST_PortNumber");

            if (testName.toUpperCase().contains("GET")){
                command += " -JREST_Path=" + props.getProperty("REST_Path_get")
                        + " -JREST_size=" + size.toString();

            } else if (testName.toUpperCase().contains("SEND")){
                command += " -JREST_Path=" + props.getProperty("REST_Path_send");

            } else if (testName.toUpperCase().contains("MINIMAL")){
                command += " -JREST_Path=" + props.getProperty("REST_Path_minimal");
            }

            else {
                throw new IllegalArgumentException("Test name must contain either 'get', 'send' or 'minimal'");
            }


        } else {
            throw new IllegalArgumentException("Test name must contain either 'SOAP' or 'REST'");
        }
        // for logs
        // command += " -l " + "\"" + "src\\main\\logs\\" + testName.replace("TestJMX\\", "").replace(".jmx", "") + ".jtl" + "\"";

        System.out.println(command);
        return command;
    }

}
