package org.bench4q.monitor.service.windows;

import org.bench4q.monitor.model.NetworkInterfaceModel;
import org.bench4q.monitor.model.NetworkInterfaceModelChild;
import org.bench4q.monitor.performance.windows.NetworkInterfaceMonitor;

public class NetworkInterfaceServiceWindows {
	private NetworkInterfaceMonitor networkInterfaceMonitor;

	public NetworkInterfaceMonitor getNetworkInterfaceMonitor() {
		return networkInterfaceMonitor;
	}

	public void setNetworkInterfaceMonitor(
			NetworkInterfaceMonitor networkInterfaceMonitor) {
		this.networkInterfaceMonitor = networkInterfaceMonitor;
	}

	public NetworkInterfaceServiceWindows() {
		this.setNetworkInterfaceMonitor(new NetworkInterfaceMonitor());
	}

	public NetworkInterfaceModel getNetworkInterfaceInfo(int idleTime) {
		NetworkInterfaceModel networkInterfaceModel = new NetworkInterfaceModel();
		String[] instances = this.getNetworkInterfaceMonitor().getInstances();
		for (String elem : instances) {
			NetworkInterfaceModelChild networkInterfaceModelChild = new NetworkInterfaceModelChild();
			networkInterfaceModelChild.setInstance(elem);
			networkInterfaceModelChild.setBytesTotalPerSecond(this
					.getNetworkInterfaceMonitor().getBytesTotalPerSecond(elem,
							idleTime));
			networkInterfaceModelChild.setBytesReceivedPerSecond(this
					.getNetworkInterfaceMonitor().getBytesReceivedPerSecond(
							elem, idleTime));
			networkInterfaceModelChild.setBytesSentPerSecond(this
					.getNetworkInterfaceMonitor().getBytesSentPerSecond(elem,
							idleTime));
			networkInterfaceModel.getNetworkList().add(
					networkInterfaceModelChild);
		}
		return networkInterfaceModel;
	}
}
