'use strict';

var messagebird;

function sendMessageSMS(targetNum, message, callback) {
    if(messagebird) {
        var messageBirdConf = config.get("messageBird");
        if(messageBirdConf) {
            messagebird = require('messagebird')(messageBirdConf.key);
        }

        var params = {
            'originator': messageBirdConf.originator,
            'recipients': targetNum,
            'body': message
        };

        messagebird.messages.create(params, function (err, response) {
            callback(err, response);
        });
    } else {
        var msg = "!!! There is no configured SMS provider in serverConfiguration !!!!";
        logger.error(msg);
        logger.error("Please configure with syntax: 'messageBird' : { 'originator' : 'Fieldtec', 'key' : 'live_key' }");
        if (typeof callback === 'function') {
            callback(msg);
        }
    }
};

module.exports = {
    sendMessageSMS: sendMessageSMS
};
