package nl.nikhef.sfp;

import java.io.IOException;

import nl.nikhef.sfp.i2c.I2CLink;
import nl.nikhef.sfp.i2c.SimI2CLink;

public class SimSFPDevice extends SFPDeviceBase {

	private final String _serial;
	private final int    _bays;
	private I2CLink[]	 _links;
	
	
	public SimSFPDevice(String serial, int bays) {
		_serial = serial;
		_bays = bays;
		_links = new I2CLink[_bays];
	}
	
	@Override
	public String getSerial() {
		return _serial;
	}

	@Override
	public int getBayCount() {
		return _bays;
	}

	@Override
	public I2CLink getLink(int bay) throws IOException {
		if (!isModulePresent(bay)) return null;
		return _links[bay];
	}

	@Override
	public boolean isModulePresent(int bay) {
		if (bay < 0 || bay > getBayCount()) return false;
		return _links[bay] != null;
	}
	
	public void placeModule(int bay) {
		_links[bay] = new SimI2CLink(String.format("SIM_%d", bay));
		sdlMgr.getProxy().sfpModuleStateChanged(this, bay);
	}

	public void removeModule(int bay) {
		_links[bay] = null;
		sdlMgr.getProxy().sfpModuleStateChanged(this, bay);
	}

	@Override
	public void shutdown() {
	}

	
	
}
