package org.bench4q.monitor.service.windows;

import org.bench4q.monitor.model.LogicalDiskModel;
import org.bench4q.monitor.model.LogicalDiskModelChild;
import org.bench4q.monitor.performance.windows.LogicalDiskMonitor;

public class LogicalDiskServiceWindows {
	private LogicalDiskMonitor logicalDiskMonitor;

	public LogicalDiskServiceWindows() {
		this.setLogicalDiskMonitor(new LogicalDiskMonitor());
	}

	public LogicalDiskMonitor getLogicalDiskMonitor() {
		return logicalDiskMonitor;
	}

	public void setLogicalDiskMonitor(LogicalDiskMonitor logicalDiskMonitor) {
		this.logicalDiskMonitor = logicalDiskMonitor;
	}

	public LogicalDiskModel getLogicalDiskInfo(int idleTime) {

		String[] instances = this.getLogicalDiskMonitor().getInstances();
		LogicalDiskModel logicalDiskModel = new LogicalDiskModel();

		for (String elem : instances) {

			LogicalDiskModelChild logicalDiskModelChild = new LogicalDiskModelChild();
			logicalDiskModelChild.setInstance(elem);
			logicalDiskModelChild.setDiskBytesPerSecond(this
					.getLogicalDiskMonitor().getDiskBytesPerSecond(elem,
							idleTime));
			logicalDiskModelChild.setDiskWriteBytesPerSecond(this
					.getLogicalDiskMonitor().getDiskWriteBytesPerSecond(elem,
							idleTime));
			logicalDiskModelChild.setDiskReadBytesPerSecond(this
					.getLogicalDiskMonitor().getDiskReadsPerSecond(elem,
							idleTime));
			logicalDiskModelChild.setAverageDiskQueueLength(this
					.getLogicalDiskMonitor().getAverageDiskQueueLength(elem,
							idleTime));
			logicalDiskModelChild.setAverageDiskReadTimeInSecond(this
					.getLogicalDiskMonitor().getAverageDiskReadQueueLength(
							elem, idleTime));

			logicalDiskModelChild.setAverageDiskTransferTimeInSecond(this
					.getLogicalDiskMonitor()
					.getAverageDiskTransferTimeInSecond(elem, idleTime));
			logicalDiskModelChild.setCurrentDiskQueueLength(this
					.getLogicalDiskMonitor().getCurrentDiskQueueLength(elem));
			logicalDiskModelChild.setAverageDiskWriteTimeInSecond(this
					.getLogicalDiskMonitor().getAverageDiskWriteTimeInSecond(
							elem, idleTime));

			logicalDiskModelChild.setDiskReadTimePercent(this
					.getLogicalDiskMonitor().getDiskReadTimePercent(elem,
							idleTime));
			logicalDiskModelChild
					.setDiskTimePercent(this.getLogicalDiskMonitor()
							.getDiskTimePercent(elem, idleTime));
			logicalDiskModelChild.setDiskWriteTimePercent(this
					.getLogicalDiskMonitor().getDiskWriteTimePercent(elem,
							idleTime));

			logicalDiskModelChild.setFreeMegabytes(this.getLogicalDiskMonitor()
					.getFreeMegabytes(elem));
			logicalDiskModelChild.setFreeSpacePercent(this
					.getLogicalDiskMonitor().getFreeSpacePercent(elem));
			logicalDiskModelChild
					.setIdleTimePercent(this.getLogicalDiskMonitor()
							.getIdleTimePercent(elem, idleTime));

			logicalDiskModel.getLogicalDiskList().add(logicalDiskModelChild);
		}
		return logicalDiskModel;
	}

}
