package org.littleshoot.proxy;

//import org.apache.log4j.xml.DOMConfigurator;

import org.littleshoot.proxy.impl.DefaultHttpProxyServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * Launches a new HTTP proxy.
 */
public class Launcher {

    private static final Logger LOG = LoggerFactory.getLogger(Launcher.class);

    private static final String OPTION_DNSSEC = "dnssec";

    private static final String OPTION_PORT = "port";

    private static final String OPTION_HELP = "help";

    private static final String OPTION_MITM = "mitm";

    private static final String OPTION_NIC = "nic";

    /**
     * Starts the proxy from the command line.
     *
     * @param port Any command line arguments.
     */
    public static void startHttpProxyService(int port) {
        //  pollLog4JConfigurationFileIfAvailable();

        System.out.println("About to start server on port: " + port);
        HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer
                .bootstrapFromFile("./littleproxy.properties")
                .withPort(port)
                //.withTransportProtocol(TransportProtocol.UDT)
                .withAllowLocalOnly(false);


        System.out.println("About to start...");
        bootstrap.start();
    }

//    private static void pollLog4JConfigurationFileIfAvailable() {
//        File log4jConfigurationFile = new File("src/test/resources/log4j.xml");
//        if (log4jConfigurationFile.exists()) {
//            DOMConfigurator.configureAndWatch(
//                    log4jConfigurationFile.getAbsolutePath(), 15);
//        }
//    }
}
