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

module.exports = (api: IntegrationAPI) => {
	api.registerAction('overview', 'Show slide overview', require('./actions/overview'));
	api.registerAction('previous', 'Previous slide', require('./actions/previous'));
	api.registerAction('next', 'Next slide', require('./actions/next'));

	api.registerConnectionValidator('powerpoint-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 Powerpoint-Bridge');
				});
		} else validatorAPI.callback(false, 'No ip or port specified');
	});
};
