import axios from 'axios';
import { IntegrationAPI } from '../../IntegrationApi';

module.exports = (api: IntegrationAPI) => {
	api.registerAction('startStopVideo', require('./actions/startStopVideo'));
	api.registerAction('muteUnmuteAudio', require('./actions/muteUnmuteAudio'));
	api.registerAction('startStopScreenshare', require('./actions/startStopScreenshare'));
	api.registerAction('enterExitFullscreen', require('./actions/enterExitFullscreen'));
	api.registerAction('switchToSpeakerView', require('./actions/switchToSpeakerView'));
	api.registerAction('switchToGalleryView', require('./actions/switchToGalleryView'));
	api.registerAction('muteEveryoneExceptSelf', require('./actions/muteEveryoneExceptSelf'));
	api.registerAction('screenshot', require('./actions/screenshot'));

	api.registerConnectionValidator('zoom-bridge', (validatorAPI) => {
		if (validatorAPI.properties.ip != undefined && validatorAPI.properties.port != undefined) {
			axios
				.get(`http://${validatorAPI.properties.ip}:${validatorAPI.properties.port}/v1/ping`)
				.then(() => {
					validatorAPI.callback(true);
				})
				.catch(() => {
					validatorAPI.callback(false, 'Unable to reach Zoom-Bridge');
				});
		} else validatorAPI.callback(false, 'No ip or port specified');
	});
};
