package net.northking.cctp.upperComputer.driver.agent.command.data;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * WatchNetworkCommand
 */
public class NetworkCollectInfo {

    /**
     * 本数据表示指定id的网络为新增网络信息
     */
    public static final int STATE_AVAILABLE = 1;

    /**
     * 本数据表示指定id的网络信息发生变更
     */
    public static final int STATE_CAPABILITIES_CHANGED = 0;

    /**
     * 本数据表示指定id的网络正在丢失，即将不可用
     */
    public static final int STATE_LOSING = -1;

    /**
     * 本数据表示指定id的网络已经丢失，不再可用
     */
    public static final int STATE_LOST = -2;

    /**
     * 指示上次探测此网络时发现此网络具有强制网络门户。
     * Indicates that this network was found to have a captive portal in place last time it was probed.
     */
    public static final int NET_CAPABILITY_CAPTIVE_PORTAL = 17;

    /**
     * 指示这是一个能够访问运营商的 CBS 服务器的网络，用于运营商特定的服务。
     * Indicates this is a network that has the ability to reach the carrier's CBS servers, used for carrier specific services.
     */
    public static final int NET_CAPABILITY_CBS = 5;

    /**
     * 表示这是一个能够访问运营商的 DUN 或网络共享网关的网络。
     * Indicates this is a network that has the ability to reach the carrier's DUN or tethering gateway.
     */
    public static final int NET_CAPABILITY_DUN = 2;

    /**
     * 表示这是一个能够访问运营商的紧急 IMS 服务器或其他服务的网络，用于在紧急呼叫期间发出网络信令。
     * Indicates this is a network that has the ability to reach a carrier's Emergency IMS servers or other services, used for network signaling during emergency calls.
     */
    public static final int NET_CAPABILITY_EIMS = 10;

    /**
     * 指示此网络供企业使用。
     * Indicates that this network is intended for enterprise use.
     * <br>
     * 5G URSP规则可能表明所有数据都应使用专用于企业使用的连接。如果请求企业功能，则所有企业流量都将通过具有此功能的连接进行路由。
     * 5G URSP rules may indicate that all data should use a connection dedicated for enterprise use. If the enterprise capability is requested, all enterprise traffic will be routed over the connection with this capability.
     */
    public static final int NET_CAPABILITY_ENTERPRISE = 29;

    /**
     * 指示此网络可供应用使用，而不是在后台保持以便于快速网络切换的网络。
     * Indicates that this network is available for use by apps, and not a network that is being kept up in the background to facilitate fast network switching.
     */
    public static final int NET_CAPABILITY_FOREGROUND = 19;

    /**
     * 表示这是一个能够访问运营商FOTA门户的网络，用于无线更新。
     * Indicates this is a network that has the ability to reach the carrier's FOTA portal, used for over the air updates.
     */
    public static final int NET_CAPABILITY_FOTA = 3;

    /**
     * 指示此网络已连接到汽车音响主机。
     * Indicates that this network is connected to an automotive head unit.
     */
    public static final int NET_CAPABILITY_HEAD_UNIT = 32;

    /**
     * 指示这是一个能够访问运营商的初始连接服务器的网络。
     * Indicates this is a network that has the ability to reach a carrier's Initial Attach servers.
     */
    public static final int NET_CAPABILITY_IA = 7;

    /**
     * 指示这是一个能够访问运营商的 IMS 服务器的网络，用于网络注册和信令。
     * Indicates this is a network that has the ability to reach the carrier's IMS servers, used for network registration and signaling.
     */
    public static final int NET_CAPABILITY_IMS = 4;

    /**
     * 指示此网络应该能够访问互联网。
     * Indicates that this network should be able to reach the internet.
     */
    public static final int NET_CAPABILITY_INTERNET = 12;

    /**
     * 指示这是一个能够访问运营商的关键任务服务器的网络。
     * Indicates this is a network that has the ability to reach a carrier's Mission Critical servers.
     */
    public static final int NET_CAPABILITY_MCX = 23;

    /**
     * 指示这是一个能够访问运营商的 MMSC 以发送和接收彩信的网络。
     * Indicates this is a network that has the ability to reach the carrier's MMSC for sending and receiving MMS messages.
     */
    public static final int NET_CAPABILITY_MMS = 0;

    /**
     * 指示此网络能够支持 MMTEL（多媒体电话服务）。
     * Indicates that this network has ability to support MMTEL (Multimedia Telephony service).
     */
    public static final int NET_CAPABILITY_MMTEL = 33;

    /**
     * 指示此网络未拥塞。
     * Indicates that this network is not congested.
     * <br>
     * 当网络拥塞时，应用程序应延迟可以在以后完成的网络流量，例如上传分析。
     * When a network is congested, applications should defer network traffic that can be done at a later time, such as uploading analytics.
     */
    public static final int NET_CAPABILITY_NOT_CONGESTED = 20;

    /**
     * 指示此网络不按流量计费。
     * Indicates that this network is unmetered.
     */
    public static final int NET_CAPABILITY_NOT_METERED = 11;

    /**
     * 指示此网络可用于常规用途。如果未设置，则应用程序不应尝试在此网络上进行通信。请注意，这只是提供信息，而不是执行 - 执行是通过其他方式处理的。默认设置。
     * Indicates that this network is available for general use. If this is not set applications should not attempt to communicate on this network. Note that this is simply informative and not enforcement - enforcement is handled via other means. Set by default.
     */
    public static final int NET_CAPABILITY_NOT_RESTRICTED = 13;

    /**
     * 指示此网络未漫游。
     * Indicates that this network is not roaming.
     */
    public static final int NET_CAPABILITY_NOT_ROAMING = 18;

    /**
     * 指示此网络当前未挂起。
     * Indicates that this network is not currently suspended.
     * <br>
     * 当网络挂起时，网络的 IP 地址和在网络上建立的任何连接仍然有效，但网络暂时无法传输数据。例如，如果蜂窝网络遇到暂时的信号丢失，例如在通过隧道时等，则可能会发生这种情况。具有此功能的网络不会挂起，因此应能够传输数据。
     * When a network is suspended, the network's IP addresses and any connections established on the network remain valid, but the network is temporarily unable to transfer data. This can happen, for example, if a cellular network experiences a temporary loss of signal, such as when driving through a tunnel, etc. A network with this capability is not suspended, so is expected to be able to transfer data.
     */
    public static final int NET_CAPABILITY_NOT_SUSPENDED = 21;

    /**
     * 指示此网络不是 VPN。此功能是默认设置的，应为 VPN 网络显式清除。
     * Indicates that this network is not a VPN. This capability is set by default and should be explicitly cleared for VPN networks.
     */
    public static final int NET_CAPABILITY_NOT_VPN = 15;

    /**
     * 指示此网络应能够确定互联网带宽的优先级。从 开始 Build.VERSION_CODES#UPSIDE_DOWN_CAKE ，请求此功能需要在 ConnectivityManager#requestNetwork 自认证网络功能中进行声明。
     * Indicates that this network should be able to prioritize bandwidth for the internet. Starting with Build.VERSION_CODES#UPSIDE_DOWN_CAKE, requesting this capability with ConnectivityManager#requestNetwork requires declaration in the self-certified network capabilities.
     */
    public static final int NET_CAPABILITY_PRIORITIZE_BANDWIDTH = 35;

    /**
     * 指示此网络应该能够确定互联网延迟的优先级。从 开始 Build.VERSION_CODES#UPSIDE_DOWN_CAKE ，请求此功能需要在 ConnectivityManager#requestNetwork 自认证网络功能中进行声明。
     * Indicates that this network should be able to prioritize latency for the internet. Starting with Build.VERSION_CODES#UPSIDE_DOWN_CAKE, requesting this capability with ConnectivityManager#requestNetwork requires declaration in the self-certified network capabilities.
     */
    public static final int NET_CAPABILITY_PRIORITIZE_LATENCY = 34;

    /**
     * 指示这是一个能够访问运营商的 RCS 服务器（用于富通信服务）的网络。
     * Indicates this is a network that has the ability to reach a carrier's RCS servers, used for Rich Communication Services.
     */
    public static final int NET_CAPABILITY_RCS = 8;

    /**
     * 指示这是一个能够访问运营商的 SUPL 服务器的网络，用于检索 GPS 信息。
     * Indicates this is a network that has the ability to reach the carrier's SUPL server, used to retrieve GPS information.
     */
    public static final int NET_CAPABILITY_SUPL = 1;

    /**
     * 指示此网络暂时不按流量计费。
     * Indicates that this network is temporarily unmetered.
     * <br>
     * This capability will be set for networks that are generally metered, but are currently unmetered, e.g., because the user is in a particular area. This capability can be changed at any time. When it is removed, applications are responsible for stopping any data transfer that should not occur on a metered network. Note that most apps should use NET_CAPABILITY_NOT_METERED instead. For more information, see https://developer.android.com/about/versions/11/features/5g#meteredness.
     * 此功能将为通常按流量计费但当前未按流量计费的网络设置，例如，因为用户位于特定区域。可以随时更改此功能。删除后，应用程序负责停止不应在按流量计费的网络上发生的任何数据传输。请注意，大多数应用应改为使用 NET_CAPABILITY_NOT_METERED 。有关详细信息，请参阅 https://developer.android.com/about/versions/11/features/5g#meteredness。
     */
    public static final int NET_CAPABILITY_TEMPORARILY_NOT_METERED = 25;

    /**
     * 指示用户已指示对此网络的隐式信任。这通常意味着它是SIM选择的运营商，插入的以太网，配对的BT设备或用户要求连接的wifi。不受信任的网络可能仅限于未知的 wifi AP。
     * Indicates that the user has indicated implicit trust of this network. This generally means it's a sim-selected carrier, a plugged in ethernet, a paired BT device or a wifi the user asked to connect to. Untrusted networks are probably limited to unknown wifi AP. Set by default.
     */
    public static final int NET_CAPABILITY_TRUSTED = 14;

    /**
     * 指示已成功验证此网络上的连接。例如，对于具有NET_CAPABILITY_INTERNET的网络，这意味着已成功检测到互联网连接。
     * Indicates that connectivity on this network was successfully validated. For example, for a network with NET_CAPABILITY_INTERNET, it means that Internet connectivity was successfully detected.
     */
    public static final int NET_CAPABILITY_VALIDATED = 16;

    /**
     * 指示这是一个能够到达 Wi-Fi 直接对等方的网络。
     * Indicates this is a network that has the ability to reach a Wi-Fi direct peer.
     */
    public static final int NET_CAPABILITY_WIFI_P2P = 6;

    /**
     * 表示这是一个能够访问运营商的 XCAP 服务器（用于配置和控制）的网络。
     * Indicates this is a network that has the ability to reach a carrier's XCAP servers, used for configuration and control.
     */
    public static final int NET_CAPABILITY_XCAP = 9;

    /**
     * 企业功能标识符 1.它将用于唯一标识特定的企业网络。
     * Enterprise capability identifier 1. It will be used to uniquely identify specific enterprise network.
     */
    public static final int NET_ENTERPRISE_ID_1 = 1;

    /**
     * 企业功能标识符 2.它将用于唯一标识特定的企业网络。
     * Enterprise capability identifier 2. It will be used to uniquely identify specific enterprise network.
     */
    public static final int NET_ENTERPRISE_ID_2 = 2;

    /**
     * 企业功能标识符 3.它将用于唯一标识特定的企业网络。
     * Enterprise capability identifier 3. It will be used to uniquely identify specific enterprise network.
     */
    public static final int NET_ENTERPRISE_ID_3 = 3;

    /**
     * 企业功能标识符 4.它将用于唯一标识特定的企业网络。
     * Enterprise capability identifier 4. It will be used to uniquely identify specific enterprise network.
     */
    public static final int NET_ENTERPRISE_ID_4 = 4;

    /**
     * 企业功能标识符 5.它将用于唯一标识特定的企业网络。
     * Enterprise capability identifier 5. It will be used to uniquely identify specific enterprise network.
     */
    public static final int NET_ENTERPRISE_ID_5 = 5;

    /**
     * 指示未提供信号强度的魔术值。始终满足指定此值的请求。
     * Magic value that indicates no signal strength provided. A request specifying this value is always satisfied.
     */
    public static final int SIGNAL_STRENGTH_UNSPECIFIED = -2147483648;

    /**
     * 指示此网络使用蓝牙传输。
     * Indicates this network uses a Bluetooth transport.
     */
    public static final int TRANSPORT_BLUETOOTH = 2;

    /**
     * 指示此网络使用手机网络传输。
     * Indicates this network uses a Cellular transport.
     */
    public static final int TRANSPORT_CELLULAR = 0;

    /**
     * 指示此网络使用以太网传输。
     * Indicates this network uses an Ethernet transport.
     */
    public static final int TRANSPORT_ETHERNET = 3;

    /**
     * 指示此网络使用 LoWPAN 传输。
     * Indicates this network uses a LoWPAN transport.
     */
    public static final int TRANSPORT_LOWPAN = 6;

    /**
     * 指示此网络基于 IPv6 的低功耗网状网络技术传输。
     * Indicates this network uses a Thread transport.
     */
    public static final int TRANSPORT_THREAD = 9;

    /**
     * 指示此网络使用 USB 传输。
     * Indicates this network uses a USB transport.
     */
    public static final int TRANSPORT_USB = 8;

    /**
     * 指示此网络使用 VPN 传输。
     * Indicates this network uses a VPN transport.
     */
    public static final int TRANSPORT_VPN = 4;

    /**
     * 指示此网络使用 Wi-Fi 传输。
     * Indicates this network uses a Wi-Fi transport.
     */
    public static final int TRANSPORT_WIFI = 1;

    /**
     * 指示此网络使用 Wi-Fi 感知传输。
     * Indicates this network uses a Wi-Fi Aware transport.
     */
    public static final int TRANSPORT_WIFI_AWARE = 5;

    public int networkId = 0;

    /**
     * 输出传输目的（状态）<br>
     * 0:更新capabilities
     * 1:onAvailable
     * -1:onLosing
     * -2:onLost
     */
    public int state = 0;

    /**
     * 连接相关属性
     */
    public int[] capabilities = new int[0];

    /**
     * 传输层信息
     */
    public int[] transport = new int[0];

    /**
     * 企业标识符集
     */
    public int[] enterpriseIds = new int[0];

    /**
     * 信号强度
     */
    public int signalStrength = SIGNAL_STRENGTH_UNSPECIFIED;

    /**
     * 与第一跃点的估计上行带宽，单位Kbps
     */
    public int linkUpstreamBandwidthKbps = -1;

    /**
     * 与第一跃点的估计下行带宽，单位Kbps
     */
    public int linkDownstreamBandwidthKbps = -1;

    /**
     * 网络接口名称
     */
    public String interfaceName = null;

    /**
     * IP地址，包含v4和v6的
     */
    public final ArrayList<String> linkAddress = new ArrayList<>();

    /**
     * DNS服务器地址<br>
     * 通常为额外设定的，自动获取时这里可能为空
     */
    public final ArrayList<String> dnsServer = new ArrayList<>();

    /**
     * 路由规则
     */
    public final ArrayList<String> routes = new ArrayList<>();

    /**
     * 是否使用私人dns
     */
    public boolean usePrivateDns = false;

    /**
     * 私人dns服务器名称
     */
    public String privateDnsServerName = null;


    /**
     * mtu，0为无效
     */
    public int mtu = 0;

    /**
     * 代理主机
     */
    public String proxyHost = null;

    /**
     * 代理主机端口
     */
    public int proxyPort = 0;

    /**
     * 代理是否有效
     */
    public boolean proxyValid = false;

    /**
     * 代理PAC规则文件地址
     */
    public String proxyPacUri = null;

    /**
     * 代理忽略列表
     */
    public final ArrayList<String> proxyExclusionList = new ArrayList<>();

    public boolean hasCapability(int capability) {
        for (int c : capabilities) {
            if (c == capability) {
                return true;
            }
        }
        return false;
    }

    public boolean hasTransport(int trans) {
        for (int t : transport) {
            if (t == trans) {
                return true;
            }
        }
        return false;
    }

    public boolean hasEnterpriseId(int id) {
        for (int e : enterpriseIds) {
            if (e == id) {
                return true;
            }
        }
        return false;
    }

    @Override
    public String toString() {
        return "NetworkCollectInfo{" +
                "networkId=" + networkId +
                ", state=" + state +
                ", capabilities=" + Arrays.toString(capabilities) +
                ", transport=" + Arrays.toString(transport) +
                ", enterpriseIds=" + Arrays.toString(enterpriseIds) +
                ", signalStrength=" + signalStrength +
                ", linkUpstreamBandwidthKbps=" + linkUpstreamBandwidthKbps +
                ", linkDownstreamBandwidthKbps=" + linkDownstreamBandwidthKbps +
                ", interfaceName='" + interfaceName + '\'' +
                ", linkAddress=" + linkAddress +
                ", dnsServer=" + dnsServer +
                ", routes=" + routes +
                ", usePrivateDns=" + usePrivateDns +
                ", privateDnsServerName='" + privateDnsServerName + '\'' +
                ", mtu=" + mtu +
                ", proxyHost='" + proxyHost + '\'' +
                ", proxyPort=" + proxyPort +
                ", proxyValid=" + proxyValid +
                ", proxyPacUri='" + proxyPacUri + '\'' +
                ", proxyExclusionList=" + proxyExclusionList +
                '}';
    }
}
