import { ConnectionValidatorAPI, IntegrationAPI } from "../../IntegrationApi";
import { MoorenTV } from "./MoorenTv";

module.exports = (Api: IntegrationAPI) => {
    Api.registerAction('startGame', 'Start game', require('./actions/startGame'))
    Api.registerAction('stopGame', 'Stop game', require('./actions/stopGame'))

    Api.registerConnectionValidator('moorentv', (validatorApi: ConnectionValidatorAPI) => {
        var { serverAddress, serverPort, adminPass } = validatorApi.properties

        var mtv = new MoorenTV({ serverAddress, serverPort, adminPass })

        mtv.ping((succeed) => {
            if (succeed) validatorApi.setInstance(mtv)
            validatorApi.callback(succeed, succeed == false ? 'Unable to connect to the MoorenTV instance' : null)
        })
    })
}