import { ConnectionValidatorAPI, IntegrationAPI } from '../../IntegrationApi';

import { default as axios } from 'axios';
import { Getiyo } from './getiyo';

module.exports = (api: IntegrationAPI) => {
	api.registerAction(
		'publishScene',
		'Publish scene',
		require('./actions/publishScene')
	);
	api.registerAction(
		'startTimeline',
		'Start timeline',
		require('./actions/startTimeline')
	);
	api.registerAction(
		'stopTimeline',
		'Stop timeline',
		require('./actions/stopTimeline')
	);
	api.registerAction(
		'pauseTimeline',
		'Pause timeline',
		require('./actions/pauseTimeline')
	);
	api.registerAction(
		'continueTimelineHold',
		'Continue timeline hold',
		require('./actions/continueTimelineHold')
	);
	api.registerAction(
		'skipTimelineBlock',
		'Skip timeline block',
		require('./actions/skipTimelineBlock')
	);
	api.registerAction(
		'jumpToTimelineSections',
		'Jump to timeline section',
		require('./actions/jumpToTimelineSections')
	);

	api.registerConnectionValidator(
		'channel',
		(ValidatorAPI: ConnectionValidatorAPI) => {
			var properties = ValidatorAPI.properties;

			var Channel = new Getiyo({
				serverProtocol: properties.protocol,
				serverAddress: properties.address,
				serverPort: properties.port,
				channelName: properties.channel,
				channelApiKey: properties.key,
			});

			Channel.checkConnection((succeed) => {
				if (succeed == true) {
					ValidatorAPI.callback(true);
					ValidatorAPI.setInstance(Channel);
				} else
					ValidatorAPI.callback(
						false,
						'Unable to find a Getiyo channel in this location.'
					);
			});
		}
	);
};

interface Channel_Properties {
	address: string;
	port: string;
	channel: string;
	key: string;
}
