package org.bench4q.monitor.service.windows;

import org.bench4q.monitor.model.PhysicalDiskModel;
import org.bench4q.monitor.model.PhysicalDiskModelChild;
import org.bench4q.monitor.performance.windows.PhysicalDiskMonitor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PhysicalDiskServiceWindows {
	private PhysicalDiskMonitor physicalDiskMonitor;

	public PhysicalDiskMonitor getPhysicalDiskrMonitor() {
		return physicalDiskMonitor;
	}
	@Autowired
	public void setPhysicalDiskrMonitor(PhysicalDiskMonitor physicalDiskrMonitor) {
		this.physicalDiskMonitor = physicalDiskrMonitor;
	}

	public PhysicalDiskModel getPhysicalDiskInfo(int idleTime) {

		PhysicalDiskModel physicalDiskModel = new PhysicalDiskModel();
		String instances[] = physicalDiskMonitor.getInstances();
		System.out.println(instances.length);
		PhysicalDiskModelChild physicalDiskModelChild = new PhysicalDiskModelChild();
		for (String elem : instances) {
			physicalDiskModelChild.setInstance(elem);
			physicalDiskModelChild
					.setAverageDiskQueueLength(physicalDiskMonitor
							.getAverageDiskQueueLength(elem, idleTime));
			physicalDiskModelChild
					.setCurrentDiskQueueLength(physicalDiskMonitor
							.getCurrentDiskQueueLength(elem));
			physicalDiskModelChild.setDiskBytesPerSecond(physicalDiskMonitor
					.getDiskBytesPerSecond(elem, idleTime));
			physicalDiskModelChild
					.setAverageDiskQueueLength(physicalDiskMonitor
							.getAverageDiskQueueLength(elem, idleTime));
			physicalDiskModelChild.setDiskTimePercent(physicalDiskMonitor
					.getDiskTimePercent(elem, idleTime));
			physicalDiskModelChild.setDiskWriteBytesPerSecond(physicalDiskMonitor.getDiskWriteBytesPerSecond(elem,idleTime));
			
			physicalDiskModel.getPhysicalDiskModelList().add(physicalDiskModelChild);
		}
		return physicalDiskModel;
	}

}
