package com.jscape.inet.proxy;

import com.jscape.util.SuppressObfuscation;

import java.util.logging.Logger;

/**
 * @author Alex Uzun
 */
@SuppressObfuscation
public enum ProxyType {

    HTTP("HTTP", java.net.Proxy.Type.HTTP) {
        @Override
        public Proxy proxy() {
            return new HttpProxy(Logger.getLogger("com.jscape.inet.proxy"));
        }
    },
    SOCKS$("SOCKS4", java.net.Proxy.Type.SOCKS) {
        @Override
        public Proxy proxy() {
            return new Socks4Proxy(Logger.getLogger("com.jscape.inet.proxy"));
        }
    },
    SOCKS5("SOCKS5", java.net.Proxy.Type.SOCKS) {
        @Override
        public Proxy proxy() {
            return new Socks5Proxy(Logger.getLogger("com.jscape.inet.proxy"));
        }
    };

    public final String name;
    public final java.net.Proxy.Type type;

    public static ProxyType forName(String name) {
        for (ProxyType candidate : values()) {
            if (candidate.name.equalsIgnoreCase(name)) {
                return candidate;
            }
        }

        throw new IllegalArgumentException(String.format("Unsupported proxy type: '%s'.", name));
    }

    ProxyType(String name, java.net.Proxy.Type type) {
        this.name = name;
        this.type = type;
    }

    public abstract Proxy proxy();

}
