import { ConnectionValidatorAPI, IntegrationAPI } from '../../IntegrationApi';
import { default as axios } from 'axios';
import { WirecastConnection } from './WirecastConnection';

//TODO: --------------- TO IMPLEMENT ---------------
//TODO: Transition speed

module.exports = (api: IntegrationAPI) => {
	api.registerAction('setLiveByName', require('./actions/setLiveByName'));
	api.registerAction('clearLayer', require('./actions/clearLayer'));
	api.registerAction('multiShot', require('./actions/multiShot'));
	api.registerAction('clearIfLive', require('./actions/clearIfLive'));
	api.registerAction('transitionSpeed', require('./actions/transitionSpeed'));
	api.registerAction('go', require('./actions/go'));
	api.registerAction('setBroadcasting', require('./actions/setBroadcasting'));
	api.registerAction('setRecording', require('./actions/setRecording'));
	api.registerAction('setAutoLive', require('./actions/setAutoLive'));

	api.registerConnectionValidator(
		'wirecast-bridge',
		(ValidatorAPI: ConnectionValidatorAPI) => {
			var instance = ValidatorAPI.instance;
			if (instance == undefined) {
				instance = new WirecastConnection();
			}
			instance.setHost(
				ValidatorAPI.properties.ip,
				ValidatorAPI.properties.port
			);

			ValidatorAPI.setInstance(instance);
			instance.ping((state: boolean) => {
				ValidatorAPI.callback(
					state,
					state ? null : 'Unable to reach Wirecast-Bridge'
				);
			});
		}
	);
};
