// JavaScript Document
//V1.0.0
exports.onesignal_deleteuser = async function (options) {

    // get appid
    const appid = this.parseRequired(options.appid, '*', 'No app ID entered')
    console.log(options.appid + " => " + appid)

    let aliasLabel = this.parseOptional(options.alias_label, '*', '')
    console.log(options.alias_label + " => " + aliasLabel)

    let aliasId = this.parseOptional(options.alias_id, '*', '')
    console.log(options.alias_id + " => " + aliasId)

    const fetch = require('node-fetch');

    const url = `https://api.onesignal.com/apps/${appid}/users/by/${aliasLabel}/${aliasId}`;
    const os_options = { method: 'DELETE', headers: { accept: 'application/json', Authorization: `Basic ${process.env.ONESIGNAL_REST_API_KEY}` } };

    return fetch(url, os_options)
        .then(res => {

            return res.json().then(json => {
                json.status = res.status; // Add status to json response
                return json;
            });
        })
        .catch(err => console.error('Error:', err));
}

