"use strict";
/**
 * Copyright © 2018 Emu Analytics
 */
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = exports.builder = exports.desc = exports.command = void 0;
const utils_1 = require("../../utils");
exports.command = ['send <id>'];
exports.desc = 'Send a notification to a contact point';
const builder = (args) => {
    return args
        .positional('id', {
        describe: 'Contact point id',
        type: 'string'
    })
        .option('template', { description: 'Notification template', type: 'string' })
        .option('subject', { description: 'Notification subject', type: 'string' })
        .option('recipients', { description: 'Notification recipients (comma separated)', type: 'array' })
        .option('data', { description: 'Notification data (JSON-formatted)', type: 'string', default: '{}' });
};
exports.builder = builder;
const handler = ({ client, format, id, template, subject, recipients, data }) => __awaiter(void 0, void 0, void 0, function* () {
    try {
        const resource = yield (0, utils_1.resolveResource)(id, client.contactpoints);
        yield client.contactpoints.send(resource.id, {
            subject,
            template,
            recipients,
            data: JSON.parse(data)
        });
        (0, utils_1.logDetail)('Notification sent');
    }
    catch (e) {
        (0, utils_1.logError)(e);
    }
});
exports.handler = handler;
//# sourceMappingURL=send.js.map