/**
 * Copyright (c) 2014 Etherios, a Division of Digi International, Inc.
 * All rights not expressly granted are reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Etherios 11001 Bren Road East, Minnetonka, MN 55343
 * =======================================================================
 */
package com.etherios.connector.devicerequest;

import com.etherios.connector.core.events.ConnectionEvent;
import com.etherios.connector.core.events.DataPointEvent;
import com.etherios.connector.core.events.DataPushEvent;
import com.etherios.connector.core.events.EventsListener;
import com.etherios.connector.core.events.FileSystemEvent;
import com.etherios.connector.core.events.FirmwareEvent;
import com.etherios.connector.core.events.RCIEvent;
import com.etherios.connector.core.log.Logger;
import com.etherios.connector.emulator.CloudConnector;

/**
 * Class to manage the Device Cloud events.
 *
 * <p>It listens to the Cloud Connector events, by implementing the
 * {@link EventsListener} interface.</p>
 */
public class ConnectorEventsListener implements EventsListener {

	/* Constants */

	public static final String LOGGER_PREFIX = "[APP] ";

	/* Variables */

	private final CloudConnector connector;

	/**
	 * Class constructor. Instances a new <code>ConnectorEventsListener</code> 
	 * to manage the Cloud Connector events.
	 *
	 * @param connector The Cloud Connector object.
	 */
	public ConnectorEventsListener(CloudConnector connector) {
		this.connector = connector;
	}

	@Override
	public void notifyConnectionEvent(ConnectionEvent event) {
		switch (event.getConnectionEventType()) {
			case ConnectionEvent.CONNECTION_STARTING:
				System.out.println("Cloud Connector is connecting...");
				break;
			case ConnectionEvent.CONNECTION_CONNECTED:
				System.out.println("Cloud Connector is CONNECTED!");
				break;
			case ConnectionEvent.CONNECTION_DISCONNECTED:
				System.out.println("Cloud Connector is DISCONNECTED!");
				break;
			case ConnectionEvent.CONNECTION_ERROR:
				ConnectionEvent.ConnectionErrorEvent errorEvent = (ConnectionEvent.ConnectionErrorEvent) event;
				Logger.logSystemError(connector.getLogger(), LOGGER_PREFIX + errorEvent.getEventLogString() 
						+ " (Error: " + errorEvent.getConnectionErrorType() + ")");
				break;
			default:
				Logger.logSystemError(connector.getLogger(), LOGGER_PREFIX + "Unknown connection event type: " 
						+ event.getConnectionEventType());
				break;
		}
	}
	
	@Override
	public void notifyDataPointEvent(DataPointEvent event) {
	}

	@Override
	public void notifyDataPushEvent(DataPushEvent event) {
	}

	@Override
	public void notifyFileSystemEvent(FileSystemEvent event) {
	}

	@Override
	public void notifyRCIEvent(RCIEvent event) {
	}

	@Override
	public void notifyFirmwareEvent(FirmwareEvent event) {
	}
}
