process.chdir(__dirname);
const Settings = require('./lib/settings');
const settings = new Settings();
const windowsService = require('./lib/windowsService');

const serviceName = settings.getOrDefault('windowsService.name', 'pyrusConnectResponder');
const serviceEnvName = serviceName.toUpperCase();
const retryWait = settings.getOrDefault('windowsService.retryWaitSeconds', 10);
const retryWithinFiveMinutes = settings.getOrDefault('windowsService.retryWithinPeriod', 24);
const retryMaxLimit = settings.getOrDefault('windowsService.retryMax');

const serviceInfo = {
    name: serviceName,
    description: "Black Pear clinical system responder for pyrusConnect",
    script: __filename,
    wait: retryWait,
    grow: 0,
    maxRestarts: retryWithinFiveMinutes,
    env: {
        name: serviceEnvName,
        value: "AUTO"
    },
    flags: "--no-deprecation"
};

if (retryMaxLimit && retryMaxLimit > 0) {
    serviceInfo.maxRetries = retryMaxLimit;
}

if (!windowsService.installMode(serviceInfo)) {
    const responder = require('./lib/clinicalLibraryResponder');
    responder(serviceEnvName, settings);
}

