package org.jivesoftware.smack.proxy;

import javax.net.SocketFactory;

public class ProxyInfo {
   private String proxyAddress;
   private int proxyPort;
   private String proxyUsername;
   private String proxyPassword;
   private ProxyInfo.ProxyType proxyType;

   public ProxyInfo(ProxyInfo.ProxyType pType, String pHost, int pPort, String pUser, String pPass) {
      this.proxyType = pType;
      this.proxyAddress = pHost;
      this.proxyPort = pPort;
      this.proxyUsername = pUser;
      this.proxyPassword = pPass;
   }

   public static ProxyInfo forHttpProxy(String pHost, int pPort, String pUser, String pPass) {
      return new ProxyInfo(ProxyInfo.ProxyType.HTTP, pHost, pPort, pUser, pPass);
   }

   public static ProxyInfo forSocks4Proxy(String pHost, int pPort, String pUser, String pPass) {
      return new ProxyInfo(ProxyInfo.ProxyType.SOCKS4, pHost, pPort, pUser, pPass);
   }

   public static ProxyInfo forSocks5Proxy(String pHost, int pPort, String pUser, String pPass) {
      return new ProxyInfo(ProxyInfo.ProxyType.SOCKS5, pHost, pPort, pUser, pPass);
   }

   public static ProxyInfo forNoProxy() {
      return new ProxyInfo(ProxyInfo.ProxyType.NONE, (String)null, 0, (String)null, (String)null);
   }

   public static ProxyInfo forDefaultProxy() {
      return new ProxyInfo(ProxyInfo.ProxyType.NONE, (String)null, 0, (String)null, (String)null);
   }

   public ProxyInfo.ProxyType getProxyType() {
      return this.proxyType;
   }

   public String getProxyAddress() {
      return this.proxyAddress;
   }

   public int getProxyPort() {
      return this.proxyPort;
   }

   public String getProxyUsername() {
      return this.proxyUsername;
   }

   public String getProxyPassword() {
      return this.proxyPassword;
   }

   public SocketFactory getSocketFactory() {
      if (this.proxyType == ProxyInfo.ProxyType.NONE) {
         return new DirectSocketFactory();
      } else if (this.proxyType == ProxyInfo.ProxyType.HTTP) {
         return new HTTPProxySocketFactory(this);
      } else if (this.proxyType == ProxyInfo.ProxyType.SOCKS4) {
         return new Socks4ProxySocketFactory(this);
      } else {
         return this.proxyType == ProxyInfo.ProxyType.SOCKS5 ? new Socks5ProxySocketFactory(this) : null;
      }
   }

   public static enum ProxyType {
      NONE,
      HTTP,
      SOCKS4,
      SOCKS5;
   }
}
