package de.ctdo.bunti.dao;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.ctdo.bunti.model.*;
import org.springframework.stereotype.Repository;

@Repository
public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
    private static final Logger LOGGER = LoggerFactory.getLogger(BuntiDevicesDAOImpl.class);
	private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
	
	public BuntiDevicesDAOImpl() {
		addDummyDevices();
	}


	private void addDummyDevices() {
		int deviceID = 0;
		
		devices.add(new Par56Spot(deviceID++, 1, "Par56 Lampe 1"));
		devices.add(new Par56Spot(deviceID++, 6, "Par56 Lampe 2"));
		devices.add(new Par56Spot(deviceID++, 11, "Par56 Lampe 3"));
		devices.add(new Par56Spot(deviceID++, 16, "Par56 Lampe 4"));
		devices.add(new Strobe1500(deviceID++, 21, "Stroboskop 1"));
		devices.add(new Par56Spot(deviceID, 508, "Par56 Lampe 5"));
		LOGGER.debug("added dummy devices in DAO");
	}


	@Override
	public Collection<BuntiDMXDevice> getAllDMXDevices() {
		List<BuntiDMXDevice> list = new ArrayList<BuntiDMXDevice>();
		for (BuntiDevice device : devices) {
			if( device instanceof BuntiDMXDevice ) {
                list.add((BuntiDMXDevice) device);
			}
		}
		return list;
	}

    @Override
    public Collection<BuntiDevice> getAllDevices() {
        return Collections.unmodifiableCollection(devices);
    }
	
	@Override
	public BuntiDevice getDeviceById(int deviceId) {
		for (BuntiDevice dev : devices) {
			if(dev.getDeviceId() == deviceId) {
				return dev;
			}
		}
		return null;
	}

}
