package de.ctdo.bunti.model;

import de.ctdo.bunti.dmx.DMX;
import de.ctdo.bunti.dmx.DMXChannel;

public class Par56Spot extends BuntiDMXDevice {

    private static final String CHANNEL_MODE = "mode";
    private static final String CHANNEL_RED = "red";
    private static final String CHANNEL_GREEN = "green";
    private static final String CHANNEL_BLUE = "blue";
    private static final String CHANNEL_SPEED = "speed";

    public Par56Spot(int deviceId, int startAddress, String deviceName) {
        super(deviceId, startAddress, deviceName);
        int offset = 0;
        addChannel(new DMXChannel(offset++, CHANNEL_MODE));
        addChannel(new DMXChannel(offset++, CHANNEL_RED));
        addChannel(new DMXChannel(offset++, CHANNEL_GREEN));
        addChannel(new DMXChannel(offset++, CHANNEL_BLUE));
        addChannel(new DMXChannel(offset, CHANNEL_SPEED));
    }

    public final void setColorRed(int value) {
        setChannelValueByName(CHANNEL_RED, value);
    }

    public final void setColorGreen(int value) {
        setChannelValueByName(CHANNEL_GREEN, value);
    }

    public final void setColorBlue(int value) {
        setChannelValueByName(CHANNEL_BLUE, value);
    }

    public final int getColorRed() {
        return getChannelValueByName(CHANNEL_RED);
    }

    public final int getColorGreen() {
        return getChannelValueByName(CHANNEL_GREEN);
    }

    public final int getColorBlue() {
        return getChannelValueByName(CHANNEL_BLUE);
    }

    @Override
    public final void switchOff() {
        setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN);
        setColorRed(DMX.DMX_CHANNEL_VALUE_MIN);
        setColorGreen(DMX.DMX_CHANNEL_VALUE_MIN);
        setColorBlue(DMX.DMX_CHANNEL_VALUE_MIN);
        setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN);
    }

    @Override
    public final void switchOn() {
        setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN);
        setColorRed(DMX.DMX_CHANNEL_VALUE_MAX);
        setColorGreen(DMX.DMX_CHANNEL_VALUE_MAX);
        setColorBlue(DMX.DMX_CHANNEL_VALUE_MAX);
        setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN);
    }

    @Override
    public final String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Par56Spot ");
        sb.append(getDeviceId());
        sb.append(", ");
        sb.append(getDeviceName());
        sb.append(" [");
        sb.append(getColorRed());
        sb.append(",");
        sb.append(getColorGreen());
        sb.append(",");
        sb.append(getColorBlue());
        sb.append("]");
        return sb.toString();
    }

}
